zfcp_fsf.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * zfcp device driver
  4. *
  5. * Implementation of FSF commands.
  6. *
  7. * Copyright IBM Corp. 2002, 2017
  8. */
  9. #define KMSG_COMPONENT "zfcp"
  10. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  11. #include <linux/blktrace_api.h>
  12. #include <linux/slab.h>
  13. #include <scsi/fc/fc_els.h>
  14. #include "zfcp_ext.h"
  15. #include "zfcp_fc.h"
  16. #include "zfcp_dbf.h"
  17. #include "zfcp_qdio.h"
  18. #include "zfcp_reqlist.h"
  19. struct kmem_cache *zfcp_fsf_qtcb_cache;
  20. static bool ber_stop = true;
  21. module_param(ber_stop, bool, 0600);
  22. MODULE_PARM_DESC(ber_stop,
  23. "Shuts down FCP devices for FCP channels that report a bit-error count in excess of its threshold (default on)");
  24. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  25. {
  26. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  27. zfcp_qdio_siosl(adapter);
  28. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  29. "fsrth_1");
  30. }
  31. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  32. unsigned long timeout)
  33. {
  34. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  35. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  36. fsf_req->timer.expires = jiffies + timeout;
  37. add_timer(&fsf_req->timer);
  38. }
  39. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  40. {
  41. BUG_ON(!fsf_req->erp_action);
  42. fsf_req->timer.function = zfcp_erp_timeout_handler;
  43. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  44. fsf_req->timer.expires = jiffies + 30 * HZ;
  45. add_timer(&fsf_req->timer);
  46. }
  47. /* association between FSF command and FSF QTCB type */
  48. static u32 fsf_qtcb_type[] = {
  49. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  50. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  53. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  55. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  57. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  58. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  59. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  60. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  61. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  62. };
  63. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  64. {
  65. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  66. "operational because of an unsupported FC class\n");
  67. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
  68. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  69. }
  70. /**
  71. * zfcp_fsf_req_free - free memory used by fsf request
  72. * @fsf_req: pointer to struct zfcp_fsf_req
  73. */
  74. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  75. {
  76. if (likely(req->pool)) {
  77. if (likely(req->qtcb))
  78. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  79. mempool_free(req, req->pool);
  80. return;
  81. }
  82. if (likely(req->qtcb))
  83. kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
  84. kfree(req);
  85. }
  86. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  87. {
  88. unsigned long flags;
  89. struct fsf_status_read_buffer *sr_buf = req->data;
  90. struct zfcp_adapter *adapter = req->adapter;
  91. struct zfcp_port *port;
  92. int d_id = ntoh24(sr_buf->d_id);
  93. read_lock_irqsave(&adapter->port_list_lock, flags);
  94. list_for_each_entry(port, &adapter->port_list, list)
  95. if (port->d_id == d_id) {
  96. zfcp_erp_port_reopen(port, 0, "fssrpc1");
  97. break;
  98. }
  99. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  100. }
  101. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  102. struct fsf_link_down_info *link_down)
  103. {
  104. struct zfcp_adapter *adapter = req->adapter;
  105. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  106. return;
  107. atomic_or(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  108. zfcp_scsi_schedule_rports_block(adapter);
  109. if (!link_down)
  110. goto out;
  111. switch (link_down->error_code) {
  112. case FSF_PSQ_LINK_NO_LIGHT:
  113. dev_warn(&req->adapter->ccw_device->dev,
  114. "There is no light signal from the local "
  115. "fibre channel cable\n");
  116. break;
  117. case FSF_PSQ_LINK_WRAP_PLUG:
  118. dev_warn(&req->adapter->ccw_device->dev,
  119. "There is a wrap plug instead of a fibre "
  120. "channel cable\n");
  121. break;
  122. case FSF_PSQ_LINK_NO_FCP:
  123. dev_warn(&req->adapter->ccw_device->dev,
  124. "The adjacent fibre channel node does not "
  125. "support FCP\n");
  126. break;
  127. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  128. dev_warn(&req->adapter->ccw_device->dev,
  129. "The FCP device is suspended because of a "
  130. "firmware update\n");
  131. break;
  132. case FSF_PSQ_LINK_INVALID_WWPN:
  133. dev_warn(&req->adapter->ccw_device->dev,
  134. "The FCP device detected a WWPN that is "
  135. "duplicate or not valid\n");
  136. break;
  137. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  138. dev_warn(&req->adapter->ccw_device->dev,
  139. "The fibre channel fabric does not support NPIV\n");
  140. break;
  141. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  142. dev_warn(&req->adapter->ccw_device->dev,
  143. "The FCP adapter cannot support more NPIV ports\n");
  144. break;
  145. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "The adjacent switch cannot support "
  148. "more NPIV ports\n");
  149. break;
  150. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The FCP adapter could not log in to the "
  153. "fibre channel fabric\n");
  154. break;
  155. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The WWPN assignment file on the FCP adapter "
  158. "has been damaged\n");
  159. break;
  160. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "The mode table on the FCP adapter "
  163. "has been damaged\n");
  164. break;
  165. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "All NPIV ports on the FCP adapter have "
  168. "been assigned\n");
  169. break;
  170. default:
  171. dev_warn(&req->adapter->ccw_device->dev,
  172. "The link between the FCP adapter and "
  173. "the FC fabric is down\n");
  174. }
  175. out:
  176. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  177. }
  178. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  179. {
  180. struct fsf_status_read_buffer *sr_buf = req->data;
  181. struct fsf_link_down_info *ldi =
  182. (struct fsf_link_down_info *) &sr_buf->payload;
  183. switch (sr_buf->status_subtype) {
  184. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  185. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  186. zfcp_fsf_link_down_info_eval(req, ldi);
  187. break;
  188. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  189. zfcp_fsf_link_down_info_eval(req, NULL);
  190. }
  191. }
  192. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  193. {
  194. struct zfcp_adapter *adapter = req->adapter;
  195. struct fsf_status_read_buffer *sr_buf = req->data;
  196. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  197. zfcp_dbf_hba_fsf_uss("fssrh_1", req);
  198. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  199. zfcp_fsf_req_free(req);
  200. return;
  201. }
  202. zfcp_dbf_hba_fsf_uss("fssrh_4", req);
  203. switch (sr_buf->status_type) {
  204. case FSF_STATUS_READ_PORT_CLOSED:
  205. zfcp_fsf_status_read_port_closed(req);
  206. break;
  207. case FSF_STATUS_READ_INCOMING_ELS:
  208. zfcp_fc_incoming_els(req);
  209. break;
  210. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  211. break;
  212. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  213. zfcp_dbf_hba_bit_err("fssrh_3", req);
  214. if (ber_stop) {
  215. dev_warn(&adapter->ccw_device->dev,
  216. "All paths over this FCP device are disused because of excessive bit errors\n");
  217. zfcp_erp_adapter_shutdown(adapter, 0, "fssrh_b");
  218. } else {
  219. dev_warn(&adapter->ccw_device->dev,
  220. "The error threshold for checksum statistics has been exceeded\n");
  221. }
  222. break;
  223. case FSF_STATUS_READ_LINK_DOWN:
  224. zfcp_fsf_status_read_link_down(req);
  225. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  226. break;
  227. case FSF_STATUS_READ_LINK_UP:
  228. dev_info(&adapter->ccw_device->dev,
  229. "The local link has been restored\n");
  230. /* All ports should be marked as ready to run again */
  231. zfcp_erp_set_adapter_status(adapter,
  232. ZFCP_STATUS_COMMON_RUNNING);
  233. zfcp_erp_adapter_reopen(adapter,
  234. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  235. ZFCP_STATUS_COMMON_ERP_FAILED,
  236. "fssrh_2");
  237. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  238. break;
  239. case FSF_STATUS_READ_NOTIFICATION_LOST:
  240. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  241. zfcp_fc_conditional_port_scan(adapter);
  242. break;
  243. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  244. adapter->adapter_features = sr_buf->payload.word[0];
  245. break;
  246. }
  247. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  248. zfcp_fsf_req_free(req);
  249. atomic_inc(&adapter->stat_miss);
  250. queue_work(adapter->work_queue, &adapter->stat_work);
  251. }
  252. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  253. {
  254. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  255. case FSF_SQ_FCP_RSP_AVAILABLE:
  256. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  257. case FSF_SQ_NO_RETRY_POSSIBLE:
  258. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  259. return;
  260. case FSF_SQ_COMMAND_ABORTED:
  261. break;
  262. case FSF_SQ_NO_RECOM:
  263. dev_err(&req->adapter->ccw_device->dev,
  264. "The FCP adapter reported a problem "
  265. "that cannot be recovered\n");
  266. zfcp_qdio_siosl(req->adapter);
  267. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  268. break;
  269. }
  270. /* all non-return stats set FSFREQ_ERROR*/
  271. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  272. }
  273. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  274. {
  275. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  276. return;
  277. switch (req->qtcb->header.fsf_status) {
  278. case FSF_UNKNOWN_COMMAND:
  279. dev_err(&req->adapter->ccw_device->dev,
  280. "The FCP adapter does not recognize the command 0x%x\n",
  281. req->qtcb->header.fsf_command);
  282. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  283. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  284. break;
  285. case FSF_ADAPTER_STATUS_AVAILABLE:
  286. zfcp_fsf_fsfstatus_qual_eval(req);
  287. break;
  288. }
  289. }
  290. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  291. {
  292. struct zfcp_adapter *adapter = req->adapter;
  293. struct fsf_qtcb *qtcb = req->qtcb;
  294. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  295. zfcp_dbf_hba_fsf_response(req);
  296. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  297. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  298. return;
  299. }
  300. switch (qtcb->prefix.prot_status) {
  301. case FSF_PROT_GOOD:
  302. case FSF_PROT_FSF_STATUS_PRESENTED:
  303. return;
  304. case FSF_PROT_QTCB_VERSION_ERROR:
  305. dev_err(&adapter->ccw_device->dev,
  306. "QTCB version 0x%x not supported by FCP adapter "
  307. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  308. psq->word[0], psq->word[1]);
  309. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  310. break;
  311. case FSF_PROT_ERROR_STATE:
  312. case FSF_PROT_SEQ_NUMB_ERROR:
  313. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  314. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  315. break;
  316. case FSF_PROT_UNSUPP_QTCB_TYPE:
  317. dev_err(&adapter->ccw_device->dev,
  318. "The QTCB type is not supported by the FCP adapter\n");
  319. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  320. break;
  321. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  322. atomic_or(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  323. &adapter->status);
  324. break;
  325. case FSF_PROT_DUPLICATE_REQUEST_ID:
  326. dev_err(&adapter->ccw_device->dev,
  327. "0x%Lx is an ambiguous request identifier\n",
  328. (unsigned long long)qtcb->bottom.support.req_handle);
  329. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  330. break;
  331. case FSF_PROT_LINK_DOWN:
  332. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  333. /* go through reopen to flush pending requests */
  334. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  335. break;
  336. case FSF_PROT_REEST_QUEUE:
  337. /* All ports should be marked as ready to run again */
  338. zfcp_erp_set_adapter_status(adapter,
  339. ZFCP_STATUS_COMMON_RUNNING);
  340. zfcp_erp_adapter_reopen(adapter,
  341. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  342. ZFCP_STATUS_COMMON_ERP_FAILED,
  343. "fspse_8");
  344. break;
  345. default:
  346. dev_err(&adapter->ccw_device->dev,
  347. "0x%x is not a valid transfer protocol status\n",
  348. qtcb->prefix.prot_status);
  349. zfcp_qdio_siosl(adapter);
  350. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  351. }
  352. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  353. }
  354. /**
  355. * zfcp_fsf_req_complete - process completion of a FSF request
  356. * @fsf_req: The FSF request that has been completed.
  357. *
  358. * When a request has been completed either from the FCP adapter,
  359. * or it has been dismissed due to a queue shutdown, this function
  360. * is called to process the completion status and trigger further
  361. * events related to the FSF request.
  362. */
  363. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  364. {
  365. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  366. zfcp_fsf_status_read_handler(req);
  367. return;
  368. }
  369. del_timer(&req->timer);
  370. zfcp_fsf_protstatus_eval(req);
  371. zfcp_fsf_fsfstatus_eval(req);
  372. req->handler(req);
  373. if (req->erp_action)
  374. zfcp_erp_notify(req->erp_action, 0);
  375. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  376. zfcp_fsf_req_free(req);
  377. else
  378. complete(&req->completion);
  379. }
  380. /**
  381. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  382. * @adapter: pointer to struct zfcp_adapter
  383. *
  384. * Never ever call this without shutting down the adapter first.
  385. * Otherwise the adapter would continue using and corrupting s390 storage.
  386. * Included BUG_ON() call to ensure this is done.
  387. * ERP is supposed to be the only user of this function.
  388. */
  389. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  390. {
  391. struct zfcp_fsf_req *req, *tmp;
  392. LIST_HEAD(remove_queue);
  393. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  394. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  395. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  396. list_del(&req->list);
  397. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  398. zfcp_fsf_req_complete(req);
  399. }
  400. }
  401. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  402. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  403. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  404. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  405. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  406. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  407. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  408. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  409. {
  410. u32 fdmi_speed = 0;
  411. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  412. fdmi_speed |= FC_PORTSPEED_1GBIT;
  413. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  414. fdmi_speed |= FC_PORTSPEED_2GBIT;
  415. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  416. fdmi_speed |= FC_PORTSPEED_4GBIT;
  417. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  418. fdmi_speed |= FC_PORTSPEED_10GBIT;
  419. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  420. fdmi_speed |= FC_PORTSPEED_8GBIT;
  421. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  422. fdmi_speed |= FC_PORTSPEED_16GBIT;
  423. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  424. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  425. return fdmi_speed;
  426. }
  427. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  428. {
  429. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  430. struct zfcp_adapter *adapter = req->adapter;
  431. struct Scsi_Host *shost = adapter->scsi_host;
  432. struct fc_els_flogi *nsp, *plogi;
  433. /* adjust pointers for missing command code */
  434. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  435. - sizeof(u32));
  436. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  437. - sizeof(u32));
  438. if (req->data)
  439. memcpy(req->data, bottom, sizeof(*bottom));
  440. fc_host_port_name(shost) = be64_to_cpu(nsp->fl_wwpn);
  441. fc_host_node_name(shost) = be64_to_cpu(nsp->fl_wwnn);
  442. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  443. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  444. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  445. (u16)FSF_STATUS_READS_RECOM);
  446. if (fc_host_permanent_port_name(shost) == -1)
  447. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  448. zfcp_scsi_set_prot(adapter);
  449. /* no error return above here, otherwise must fix call chains */
  450. /* do not evaluate invalid fields */
  451. if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
  452. return 0;
  453. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  454. fc_host_speed(shost) =
  455. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  456. adapter->hydra_version = bottom->adapter_type;
  457. switch (bottom->fc_topology) {
  458. case FSF_TOPO_P2P:
  459. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  460. adapter->peer_wwpn = be64_to_cpu(plogi->fl_wwpn);
  461. adapter->peer_wwnn = be64_to_cpu(plogi->fl_wwnn);
  462. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  463. break;
  464. case FSF_TOPO_FABRIC:
  465. if (bottom->connection_features & FSF_FEATURE_NPIV_MODE)
  466. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  467. else
  468. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  469. break;
  470. case FSF_TOPO_AL:
  471. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  472. /* fall through */
  473. default:
  474. dev_err(&adapter->ccw_device->dev,
  475. "Unknown or unsupported arbitrated loop "
  476. "fibre channel topology detected\n");
  477. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  478. return -EIO;
  479. }
  480. return 0;
  481. }
  482. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  483. {
  484. struct zfcp_adapter *adapter = req->adapter;
  485. struct fsf_qtcb *qtcb = req->qtcb;
  486. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  487. struct Scsi_Host *shost = adapter->scsi_host;
  488. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  489. return;
  490. adapter->fsf_lic_version = bottom->lic_version;
  491. adapter->adapter_features = bottom->adapter_features;
  492. adapter->connection_features = bottom->connection_features;
  493. adapter->peer_wwpn = 0;
  494. adapter->peer_wwnn = 0;
  495. adapter->peer_d_id = 0;
  496. switch (qtcb->header.fsf_status) {
  497. case FSF_GOOD:
  498. if (zfcp_fsf_exchange_config_evaluate(req))
  499. return;
  500. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  501. dev_err(&adapter->ccw_device->dev,
  502. "FCP adapter maximum QTCB size (%d bytes) "
  503. "is too small\n",
  504. bottom->max_qtcb_size);
  505. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  506. return;
  507. }
  508. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  509. &adapter->status);
  510. break;
  511. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  512. fc_host_node_name(shost) = 0;
  513. fc_host_port_name(shost) = 0;
  514. fc_host_port_id(shost) = 0;
  515. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  516. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  517. adapter->hydra_version = 0;
  518. /* avoids adapter shutdown to be able to recognize
  519. * events such as LINK UP */
  520. atomic_or(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  521. &adapter->status);
  522. zfcp_fsf_link_down_info_eval(req,
  523. &qtcb->header.fsf_status_qual.link_down_info);
  524. if (zfcp_fsf_exchange_config_evaluate(req))
  525. return;
  526. break;
  527. default:
  528. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  529. return;
  530. }
  531. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  532. adapter->hardware_version = bottom->hardware_version;
  533. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  534. min(FC_SERIAL_NUMBER_SIZE, 17));
  535. EBCASC(fc_host_serial_number(shost),
  536. min(FC_SERIAL_NUMBER_SIZE, 17));
  537. }
  538. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  539. dev_err(&adapter->ccw_device->dev,
  540. "The FCP adapter only supports newer "
  541. "control block versions\n");
  542. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  543. return;
  544. }
  545. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  546. dev_err(&adapter->ccw_device->dev,
  547. "The FCP adapter only supports older "
  548. "control block versions\n");
  549. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  550. }
  551. }
  552. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  553. {
  554. struct zfcp_adapter *adapter = req->adapter;
  555. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  556. struct Scsi_Host *shost = adapter->scsi_host;
  557. if (req->data)
  558. memcpy(req->data, bottom, sizeof(*bottom));
  559. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  560. fc_host_permanent_port_name(shost) = bottom->wwpn;
  561. } else
  562. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  563. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  564. fc_host_supported_speeds(shost) =
  565. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  566. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  567. FC_FC4_LIST_SIZE);
  568. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  569. FC_FC4_LIST_SIZE);
  570. }
  571. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  572. {
  573. struct fsf_qtcb *qtcb = req->qtcb;
  574. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  575. return;
  576. switch (qtcb->header.fsf_status) {
  577. case FSF_GOOD:
  578. zfcp_fsf_exchange_port_evaluate(req);
  579. break;
  580. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  581. zfcp_fsf_exchange_port_evaluate(req);
  582. zfcp_fsf_link_down_info_eval(req,
  583. &qtcb->header.fsf_status_qual.link_down_info);
  584. break;
  585. }
  586. }
  587. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  588. {
  589. struct zfcp_fsf_req *req;
  590. if (likely(pool))
  591. req = mempool_alloc(pool, GFP_ATOMIC);
  592. else
  593. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  594. if (unlikely(!req))
  595. return NULL;
  596. memset(req, 0, sizeof(*req));
  597. req->pool = pool;
  598. return req;
  599. }
  600. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  601. {
  602. struct fsf_qtcb *qtcb;
  603. if (likely(pool))
  604. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  605. else
  606. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  607. if (unlikely(!qtcb))
  608. return NULL;
  609. memset(qtcb, 0, sizeof(*qtcb));
  610. return qtcb;
  611. }
  612. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  613. u32 fsf_cmd, u8 sbtype,
  614. mempool_t *pool)
  615. {
  616. struct zfcp_adapter *adapter = qdio->adapter;
  617. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  618. if (unlikely(!req))
  619. return ERR_PTR(-ENOMEM);
  620. if (adapter->req_no == 0)
  621. adapter->req_no++;
  622. INIT_LIST_HEAD(&req->list);
  623. init_timer(&req->timer);
  624. init_completion(&req->completion);
  625. req->adapter = adapter;
  626. req->fsf_command = fsf_cmd;
  627. req->req_id = adapter->req_no;
  628. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  629. if (likely(pool))
  630. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  631. else
  632. req->qtcb = zfcp_qtcb_alloc(NULL);
  633. if (unlikely(!req->qtcb)) {
  634. zfcp_fsf_req_free(req);
  635. return ERR_PTR(-ENOMEM);
  636. }
  637. req->seq_no = adapter->fsf_req_seq_no;
  638. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  639. req->qtcb->prefix.req_id = req->req_id;
  640. req->qtcb->prefix.ulp_info = 26;
  641. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  642. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  643. req->qtcb->header.req_handle = req->req_id;
  644. req->qtcb->header.fsf_command = req->fsf_command;
  645. }
  646. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  647. req->qtcb, sizeof(struct fsf_qtcb));
  648. return req;
  649. }
  650. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  651. {
  652. struct zfcp_adapter *adapter = req->adapter;
  653. struct zfcp_qdio *qdio = adapter->qdio;
  654. int with_qtcb = (req->qtcb != NULL);
  655. int req_id = req->req_id;
  656. zfcp_reqlist_add(adapter->req_list, req);
  657. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  658. req->issued = get_tod_clock();
  659. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  660. del_timer(&req->timer);
  661. /* lookup request again, list might have changed */
  662. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  663. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  664. return -EIO;
  665. }
  666. /* Don't increase for unsolicited status */
  667. if (with_qtcb)
  668. adapter->fsf_req_seq_no++;
  669. adapter->req_no++;
  670. return 0;
  671. }
  672. /**
  673. * zfcp_fsf_status_read - send status read request
  674. * @adapter: pointer to struct zfcp_adapter
  675. * @req_flags: request flags
  676. * Returns: 0 on success, ERROR otherwise
  677. */
  678. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  679. {
  680. struct zfcp_adapter *adapter = qdio->adapter;
  681. struct zfcp_fsf_req *req;
  682. struct fsf_status_read_buffer *sr_buf;
  683. struct page *page;
  684. int retval = -EIO;
  685. spin_lock_irq(&qdio->req_q_lock);
  686. if (zfcp_qdio_sbal_get(qdio))
  687. goto out;
  688. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  689. SBAL_SFLAGS0_TYPE_STATUS,
  690. adapter->pool.status_read_req);
  691. if (IS_ERR(req)) {
  692. retval = PTR_ERR(req);
  693. goto out;
  694. }
  695. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  696. if (!page) {
  697. retval = -ENOMEM;
  698. goto failed_buf;
  699. }
  700. sr_buf = page_address(page);
  701. memset(sr_buf, 0, sizeof(*sr_buf));
  702. req->data = sr_buf;
  703. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  704. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  705. retval = zfcp_fsf_req_send(req);
  706. if (retval)
  707. goto failed_req_send;
  708. goto out;
  709. failed_req_send:
  710. req->data = NULL;
  711. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  712. failed_buf:
  713. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  714. zfcp_fsf_req_free(req);
  715. out:
  716. spin_unlock_irq(&qdio->req_q_lock);
  717. return retval;
  718. }
  719. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  720. {
  721. struct scsi_device *sdev = req->data;
  722. struct zfcp_scsi_dev *zfcp_sdev;
  723. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  724. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  725. return;
  726. zfcp_sdev = sdev_to_zfcp(sdev);
  727. switch (req->qtcb->header.fsf_status) {
  728. case FSF_PORT_HANDLE_NOT_VALID:
  729. if (fsq->word[0] == fsq->word[1]) {
  730. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  731. "fsafch1");
  732. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  733. }
  734. break;
  735. case FSF_LUN_HANDLE_NOT_VALID:
  736. if (fsq->word[0] == fsq->word[1]) {
  737. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  738. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  739. }
  740. break;
  741. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  742. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  743. break;
  744. case FSF_PORT_BOXED:
  745. zfcp_erp_set_port_status(zfcp_sdev->port,
  746. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  747. zfcp_erp_port_reopen(zfcp_sdev->port,
  748. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  749. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  750. break;
  751. case FSF_LUN_BOXED:
  752. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  753. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  754. "fsafch4");
  755. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  756. break;
  757. case FSF_ADAPTER_STATUS_AVAILABLE:
  758. switch (fsq->word[0]) {
  759. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  760. zfcp_fc_test_link(zfcp_sdev->port);
  761. /* fall through */
  762. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  763. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  764. break;
  765. }
  766. break;
  767. case FSF_GOOD:
  768. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  769. break;
  770. }
  771. }
  772. /**
  773. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  774. * @scmnd: The SCSI command to abort
  775. * Returns: pointer to struct zfcp_fsf_req
  776. */
  777. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  778. {
  779. struct zfcp_fsf_req *req = NULL;
  780. struct scsi_device *sdev = scmnd->device;
  781. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  782. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  783. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  784. spin_lock_irq(&qdio->req_q_lock);
  785. if (zfcp_qdio_sbal_get(qdio))
  786. goto out;
  787. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  788. SBAL_SFLAGS0_TYPE_READ,
  789. qdio->adapter->pool.scsi_abort);
  790. if (IS_ERR(req)) {
  791. req = NULL;
  792. goto out;
  793. }
  794. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  795. ZFCP_STATUS_COMMON_UNBLOCKED)))
  796. goto out_error_free;
  797. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  798. req->data = sdev;
  799. req->handler = zfcp_fsf_abort_fcp_command_handler;
  800. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  801. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  802. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  803. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  804. if (!zfcp_fsf_req_send(req))
  805. goto out;
  806. out_error_free:
  807. zfcp_fsf_req_free(req);
  808. req = NULL;
  809. out:
  810. spin_unlock_irq(&qdio->req_q_lock);
  811. return req;
  812. }
  813. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  814. {
  815. struct zfcp_adapter *adapter = req->adapter;
  816. struct zfcp_fsf_ct_els *ct = req->data;
  817. struct fsf_qtcb_header *header = &req->qtcb->header;
  818. ct->status = -EINVAL;
  819. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  820. goto skip_fsfstatus;
  821. switch (header->fsf_status) {
  822. case FSF_GOOD:
  823. ct->status = 0;
  824. zfcp_dbf_san_res("fsscth2", req);
  825. break;
  826. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  827. zfcp_fsf_class_not_supp(req);
  828. break;
  829. case FSF_ADAPTER_STATUS_AVAILABLE:
  830. switch (header->fsf_status_qual.word[0]){
  831. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  832. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  833. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  834. break;
  835. }
  836. break;
  837. case FSF_PORT_BOXED:
  838. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  839. break;
  840. case FSF_PORT_HANDLE_NOT_VALID:
  841. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  842. /* fall through */
  843. case FSF_GENERIC_COMMAND_REJECTED:
  844. case FSF_PAYLOAD_SIZE_MISMATCH:
  845. case FSF_REQUEST_SIZE_TOO_LARGE:
  846. case FSF_RESPONSE_SIZE_TOO_LARGE:
  847. case FSF_SBAL_MISMATCH:
  848. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  849. break;
  850. }
  851. skip_fsfstatus:
  852. if (ct->handler)
  853. ct->handler(ct->handler_data);
  854. }
  855. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  856. struct zfcp_qdio_req *q_req,
  857. struct scatterlist *sg_req,
  858. struct scatterlist *sg_resp)
  859. {
  860. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  861. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  862. zfcp_qdio_set_sbale_last(qdio, q_req);
  863. }
  864. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  865. struct scatterlist *sg_req,
  866. struct scatterlist *sg_resp)
  867. {
  868. struct zfcp_adapter *adapter = req->adapter;
  869. struct zfcp_qdio *qdio = adapter->qdio;
  870. struct fsf_qtcb *qtcb = req->qtcb;
  871. u32 feat = adapter->adapter_features;
  872. if (zfcp_adapter_multi_buffer_active(adapter)) {
  873. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  874. return -EIO;
  875. qtcb->bottom.support.req_buf_length =
  876. zfcp_qdio_real_bytes(sg_req);
  877. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  878. return -EIO;
  879. qtcb->bottom.support.resp_buf_length =
  880. zfcp_qdio_real_bytes(sg_resp);
  881. zfcp_qdio_set_data_div(qdio, &req->qdio_req, sg_nents(sg_req));
  882. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  883. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  884. return 0;
  885. }
  886. /* use single, unchained SBAL if it can hold the request */
  887. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  888. zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
  889. sg_req, sg_resp);
  890. return 0;
  891. }
  892. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
  893. return -EOPNOTSUPP;
  894. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  895. return -EIO;
  896. qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
  897. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  898. zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
  899. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  900. return -EIO;
  901. qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
  902. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  903. return 0;
  904. }
  905. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  906. struct scatterlist *sg_req,
  907. struct scatterlist *sg_resp,
  908. unsigned int timeout)
  909. {
  910. int ret;
  911. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  912. if (ret)
  913. return ret;
  914. /* common settings for ct/gs and els requests */
  915. if (timeout > 255)
  916. timeout = 255; /* max value accepted by hardware */
  917. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  918. req->qtcb->bottom.support.timeout = timeout;
  919. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  920. return 0;
  921. }
  922. /**
  923. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  924. * @ct: pointer to struct zfcp_send_ct with data for request
  925. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  926. */
  927. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  928. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  929. unsigned int timeout)
  930. {
  931. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  932. struct zfcp_fsf_req *req;
  933. int ret = -EIO;
  934. spin_lock_irq(&qdio->req_q_lock);
  935. if (zfcp_qdio_sbal_get(qdio))
  936. goto out;
  937. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  938. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  939. if (IS_ERR(req)) {
  940. ret = PTR_ERR(req);
  941. goto out;
  942. }
  943. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  944. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  945. if (ret)
  946. goto failed_send;
  947. req->handler = zfcp_fsf_send_ct_handler;
  948. req->qtcb->header.port_handle = wka_port->handle;
  949. ct->d_id = wka_port->d_id;
  950. req->data = ct;
  951. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  952. ret = zfcp_fsf_req_send(req);
  953. if (ret)
  954. goto failed_send;
  955. goto out;
  956. failed_send:
  957. zfcp_fsf_req_free(req);
  958. out:
  959. spin_unlock_irq(&qdio->req_q_lock);
  960. return ret;
  961. }
  962. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  963. {
  964. struct zfcp_fsf_ct_els *send_els = req->data;
  965. struct fsf_qtcb_header *header = &req->qtcb->header;
  966. send_els->status = -EINVAL;
  967. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  968. goto skip_fsfstatus;
  969. switch (header->fsf_status) {
  970. case FSF_GOOD:
  971. send_els->status = 0;
  972. zfcp_dbf_san_res("fsselh1", req);
  973. break;
  974. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  975. zfcp_fsf_class_not_supp(req);
  976. break;
  977. case FSF_ADAPTER_STATUS_AVAILABLE:
  978. switch (header->fsf_status_qual.word[0]){
  979. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  980. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  981. case FSF_SQ_RETRY_IF_POSSIBLE:
  982. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  983. break;
  984. }
  985. break;
  986. case FSF_ELS_COMMAND_REJECTED:
  987. case FSF_PAYLOAD_SIZE_MISMATCH:
  988. case FSF_REQUEST_SIZE_TOO_LARGE:
  989. case FSF_RESPONSE_SIZE_TOO_LARGE:
  990. break;
  991. case FSF_SBAL_MISMATCH:
  992. /* should never occur, avoided in zfcp_fsf_send_els */
  993. /* fall through */
  994. default:
  995. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  996. break;
  997. }
  998. skip_fsfstatus:
  999. if (send_els->handler)
  1000. send_els->handler(send_els->handler_data);
  1001. }
  1002. /**
  1003. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1004. * @els: pointer to struct zfcp_send_els with data for the command
  1005. */
  1006. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  1007. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  1008. {
  1009. struct zfcp_fsf_req *req;
  1010. struct zfcp_qdio *qdio = adapter->qdio;
  1011. int ret = -EIO;
  1012. spin_lock_irq(&qdio->req_q_lock);
  1013. if (zfcp_qdio_sbal_get(qdio))
  1014. goto out;
  1015. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1016. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1017. if (IS_ERR(req)) {
  1018. ret = PTR_ERR(req);
  1019. goto out;
  1020. }
  1021. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1022. if (!zfcp_adapter_multi_buffer_active(adapter))
  1023. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1024. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1025. if (ret)
  1026. goto failed_send;
  1027. hton24(req->qtcb->bottom.support.d_id, d_id);
  1028. req->handler = zfcp_fsf_send_els_handler;
  1029. els->d_id = d_id;
  1030. req->data = els;
  1031. zfcp_dbf_san_req("fssels1", req, d_id);
  1032. ret = zfcp_fsf_req_send(req);
  1033. if (ret)
  1034. goto failed_send;
  1035. goto out;
  1036. failed_send:
  1037. zfcp_fsf_req_free(req);
  1038. out:
  1039. spin_unlock_irq(&qdio->req_q_lock);
  1040. return ret;
  1041. }
  1042. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1043. {
  1044. struct zfcp_fsf_req *req;
  1045. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1046. int retval = -EIO;
  1047. spin_lock_irq(&qdio->req_q_lock);
  1048. if (zfcp_qdio_sbal_get(qdio))
  1049. goto out;
  1050. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1051. SBAL_SFLAGS0_TYPE_READ,
  1052. qdio->adapter->pool.erp_req);
  1053. if (IS_ERR(req)) {
  1054. retval = PTR_ERR(req);
  1055. goto out;
  1056. }
  1057. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1058. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1059. req->qtcb->bottom.config.feature_selection =
  1060. FSF_FEATURE_NOTIFICATION_LOST |
  1061. FSF_FEATURE_UPDATE_ALERT;
  1062. req->erp_action = erp_action;
  1063. req->handler = zfcp_fsf_exchange_config_data_handler;
  1064. erp_action->fsf_req_id = req->req_id;
  1065. zfcp_fsf_start_erp_timer(req);
  1066. retval = zfcp_fsf_req_send(req);
  1067. if (retval) {
  1068. zfcp_fsf_req_free(req);
  1069. erp_action->fsf_req_id = 0;
  1070. }
  1071. out:
  1072. spin_unlock_irq(&qdio->req_q_lock);
  1073. return retval;
  1074. }
  1075. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1076. struct fsf_qtcb_bottom_config *data)
  1077. {
  1078. struct zfcp_fsf_req *req = NULL;
  1079. int retval = -EIO;
  1080. spin_lock_irq(&qdio->req_q_lock);
  1081. if (zfcp_qdio_sbal_get(qdio))
  1082. goto out_unlock;
  1083. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1084. SBAL_SFLAGS0_TYPE_READ, NULL);
  1085. if (IS_ERR(req)) {
  1086. retval = PTR_ERR(req);
  1087. goto out_unlock;
  1088. }
  1089. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1090. req->handler = zfcp_fsf_exchange_config_data_handler;
  1091. req->qtcb->bottom.config.feature_selection =
  1092. FSF_FEATURE_NOTIFICATION_LOST |
  1093. FSF_FEATURE_UPDATE_ALERT;
  1094. if (data)
  1095. req->data = data;
  1096. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1097. retval = zfcp_fsf_req_send(req);
  1098. spin_unlock_irq(&qdio->req_q_lock);
  1099. if (!retval)
  1100. wait_for_completion(&req->completion);
  1101. zfcp_fsf_req_free(req);
  1102. return retval;
  1103. out_unlock:
  1104. spin_unlock_irq(&qdio->req_q_lock);
  1105. return retval;
  1106. }
  1107. /**
  1108. * zfcp_fsf_exchange_port_data - request information about local port
  1109. * @erp_action: ERP action for the adapter for which port data is requested
  1110. * Returns: 0 on success, error otherwise
  1111. */
  1112. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1113. {
  1114. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1115. struct zfcp_fsf_req *req;
  1116. int retval = -EIO;
  1117. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1118. return -EOPNOTSUPP;
  1119. spin_lock_irq(&qdio->req_q_lock);
  1120. if (zfcp_qdio_sbal_get(qdio))
  1121. goto out;
  1122. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1123. SBAL_SFLAGS0_TYPE_READ,
  1124. qdio->adapter->pool.erp_req);
  1125. if (IS_ERR(req)) {
  1126. retval = PTR_ERR(req);
  1127. goto out;
  1128. }
  1129. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1130. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1131. req->handler = zfcp_fsf_exchange_port_data_handler;
  1132. req->erp_action = erp_action;
  1133. erp_action->fsf_req_id = req->req_id;
  1134. zfcp_fsf_start_erp_timer(req);
  1135. retval = zfcp_fsf_req_send(req);
  1136. if (retval) {
  1137. zfcp_fsf_req_free(req);
  1138. erp_action->fsf_req_id = 0;
  1139. }
  1140. out:
  1141. spin_unlock_irq(&qdio->req_q_lock);
  1142. return retval;
  1143. }
  1144. /**
  1145. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1146. * @qdio: pointer to struct zfcp_qdio
  1147. * @data: pointer to struct fsf_qtcb_bottom_port
  1148. * Returns: 0 on success, error otherwise
  1149. */
  1150. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1151. struct fsf_qtcb_bottom_port *data)
  1152. {
  1153. struct zfcp_fsf_req *req = NULL;
  1154. int retval = -EIO;
  1155. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1156. return -EOPNOTSUPP;
  1157. spin_lock_irq(&qdio->req_q_lock);
  1158. if (zfcp_qdio_sbal_get(qdio))
  1159. goto out_unlock;
  1160. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1161. SBAL_SFLAGS0_TYPE_READ, NULL);
  1162. if (IS_ERR(req)) {
  1163. retval = PTR_ERR(req);
  1164. goto out_unlock;
  1165. }
  1166. if (data)
  1167. req->data = data;
  1168. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1169. req->handler = zfcp_fsf_exchange_port_data_handler;
  1170. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1171. retval = zfcp_fsf_req_send(req);
  1172. spin_unlock_irq(&qdio->req_q_lock);
  1173. if (!retval)
  1174. wait_for_completion(&req->completion);
  1175. zfcp_fsf_req_free(req);
  1176. return retval;
  1177. out_unlock:
  1178. spin_unlock_irq(&qdio->req_q_lock);
  1179. return retval;
  1180. }
  1181. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1182. {
  1183. struct zfcp_port *port = req->data;
  1184. struct fsf_qtcb_header *header = &req->qtcb->header;
  1185. struct fc_els_flogi *plogi;
  1186. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1187. goto out;
  1188. switch (header->fsf_status) {
  1189. case FSF_PORT_ALREADY_OPEN:
  1190. break;
  1191. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1192. dev_warn(&req->adapter->ccw_device->dev,
  1193. "Not enough FCP adapter resources to open "
  1194. "remote port 0x%016Lx\n",
  1195. (unsigned long long)port->wwpn);
  1196. zfcp_erp_set_port_status(port,
  1197. ZFCP_STATUS_COMMON_ERP_FAILED);
  1198. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1199. break;
  1200. case FSF_ADAPTER_STATUS_AVAILABLE:
  1201. switch (header->fsf_status_qual.word[0]) {
  1202. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1203. /* no zfcp_fc_test_link() with failed open port */
  1204. /* fall through */
  1205. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1206. case FSF_SQ_NO_RETRY_POSSIBLE:
  1207. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1208. break;
  1209. }
  1210. break;
  1211. case FSF_GOOD:
  1212. port->handle = header->port_handle;
  1213. atomic_or(ZFCP_STATUS_COMMON_OPEN |
  1214. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1215. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1216. &port->status);
  1217. /* check whether D_ID has changed during open */
  1218. /*
  1219. * FIXME: This check is not airtight, as the FCP channel does
  1220. * not monitor closures of target port connections caused on
  1221. * the remote side. Thus, they might miss out on invalidating
  1222. * locally cached WWPNs (and other N_Port parameters) of gone
  1223. * target ports. So, our heroic attempt to make things safe
  1224. * could be undermined by 'open port' response data tagged with
  1225. * obsolete WWPNs. Another reason to monitor potential
  1226. * connection closures ourself at least (by interpreting
  1227. * incoming ELS' and unsolicited status). It just crosses my
  1228. * mind that one should be able to cross-check by means of
  1229. * another GID_PN straight after a port has been opened.
  1230. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1231. */
  1232. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1233. if (req->qtcb->bottom.support.els1_length >=
  1234. FSF_PLOGI_MIN_LEN)
  1235. zfcp_fc_plogi_evaluate(port, plogi);
  1236. break;
  1237. case FSF_UNKNOWN_OP_SUBTYPE:
  1238. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1239. break;
  1240. }
  1241. out:
  1242. put_device(&port->dev);
  1243. }
  1244. /**
  1245. * zfcp_fsf_open_port - create and send open port request
  1246. * @erp_action: pointer to struct zfcp_erp_action
  1247. * Returns: 0 on success, error otherwise
  1248. */
  1249. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1250. {
  1251. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1252. struct zfcp_port *port = erp_action->port;
  1253. struct zfcp_fsf_req *req;
  1254. int retval = -EIO;
  1255. spin_lock_irq(&qdio->req_q_lock);
  1256. if (zfcp_qdio_sbal_get(qdio))
  1257. goto out;
  1258. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1259. SBAL_SFLAGS0_TYPE_READ,
  1260. qdio->adapter->pool.erp_req);
  1261. if (IS_ERR(req)) {
  1262. retval = PTR_ERR(req);
  1263. goto out;
  1264. }
  1265. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1266. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1267. req->handler = zfcp_fsf_open_port_handler;
  1268. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1269. req->data = port;
  1270. req->erp_action = erp_action;
  1271. erp_action->fsf_req_id = req->req_id;
  1272. get_device(&port->dev);
  1273. zfcp_fsf_start_erp_timer(req);
  1274. retval = zfcp_fsf_req_send(req);
  1275. if (retval) {
  1276. zfcp_fsf_req_free(req);
  1277. erp_action->fsf_req_id = 0;
  1278. put_device(&port->dev);
  1279. }
  1280. out:
  1281. spin_unlock_irq(&qdio->req_q_lock);
  1282. return retval;
  1283. }
  1284. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1285. {
  1286. struct zfcp_port *port = req->data;
  1287. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1288. return;
  1289. switch (req->qtcb->header.fsf_status) {
  1290. case FSF_PORT_HANDLE_NOT_VALID:
  1291. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1292. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1293. break;
  1294. case FSF_ADAPTER_STATUS_AVAILABLE:
  1295. break;
  1296. case FSF_GOOD:
  1297. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1298. break;
  1299. }
  1300. }
  1301. /**
  1302. * zfcp_fsf_close_port - create and send close port request
  1303. * @erp_action: pointer to struct zfcp_erp_action
  1304. * Returns: 0 on success, error otherwise
  1305. */
  1306. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1307. {
  1308. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1309. struct zfcp_fsf_req *req;
  1310. int retval = -EIO;
  1311. spin_lock_irq(&qdio->req_q_lock);
  1312. if (zfcp_qdio_sbal_get(qdio))
  1313. goto out;
  1314. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1315. SBAL_SFLAGS0_TYPE_READ,
  1316. qdio->adapter->pool.erp_req);
  1317. if (IS_ERR(req)) {
  1318. retval = PTR_ERR(req);
  1319. goto out;
  1320. }
  1321. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1322. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1323. req->handler = zfcp_fsf_close_port_handler;
  1324. req->data = erp_action->port;
  1325. req->erp_action = erp_action;
  1326. req->qtcb->header.port_handle = erp_action->port->handle;
  1327. erp_action->fsf_req_id = req->req_id;
  1328. zfcp_fsf_start_erp_timer(req);
  1329. retval = zfcp_fsf_req_send(req);
  1330. if (retval) {
  1331. zfcp_fsf_req_free(req);
  1332. erp_action->fsf_req_id = 0;
  1333. }
  1334. out:
  1335. spin_unlock_irq(&qdio->req_q_lock);
  1336. return retval;
  1337. }
  1338. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1339. {
  1340. struct zfcp_fc_wka_port *wka_port = req->data;
  1341. struct fsf_qtcb_header *header = &req->qtcb->header;
  1342. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1343. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1344. goto out;
  1345. }
  1346. switch (header->fsf_status) {
  1347. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1348. dev_warn(&req->adapter->ccw_device->dev,
  1349. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1350. /* fall through */
  1351. case FSF_ADAPTER_STATUS_AVAILABLE:
  1352. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1353. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1354. break;
  1355. case FSF_GOOD:
  1356. wka_port->handle = header->port_handle;
  1357. /* fall through */
  1358. case FSF_PORT_ALREADY_OPEN:
  1359. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1360. }
  1361. out:
  1362. wake_up(&wka_port->completion_wq);
  1363. }
  1364. /**
  1365. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1366. * @wka_port: pointer to struct zfcp_fc_wka_port
  1367. * Returns: 0 on success, error otherwise
  1368. */
  1369. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1370. {
  1371. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1372. struct zfcp_fsf_req *req;
  1373. unsigned long req_id = 0;
  1374. int retval = -EIO;
  1375. spin_lock_irq(&qdio->req_q_lock);
  1376. if (zfcp_qdio_sbal_get(qdio))
  1377. goto out;
  1378. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1379. SBAL_SFLAGS0_TYPE_READ,
  1380. qdio->adapter->pool.erp_req);
  1381. if (IS_ERR(req)) {
  1382. retval = PTR_ERR(req);
  1383. goto out;
  1384. }
  1385. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1386. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1387. req->handler = zfcp_fsf_open_wka_port_handler;
  1388. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1389. req->data = wka_port;
  1390. req_id = req->req_id;
  1391. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1392. retval = zfcp_fsf_req_send(req);
  1393. if (retval)
  1394. zfcp_fsf_req_free(req);
  1395. out:
  1396. spin_unlock_irq(&qdio->req_q_lock);
  1397. if (!retval)
  1398. zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id);
  1399. return retval;
  1400. }
  1401. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1402. {
  1403. struct zfcp_fc_wka_port *wka_port = req->data;
  1404. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1405. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1406. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1407. }
  1408. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1409. wake_up(&wka_port->completion_wq);
  1410. }
  1411. /**
  1412. * zfcp_fsf_close_wka_port - create and send close wka port request
  1413. * @wka_port: WKA port to open
  1414. * Returns: 0 on success, error otherwise
  1415. */
  1416. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1417. {
  1418. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1419. struct zfcp_fsf_req *req;
  1420. unsigned long req_id = 0;
  1421. int retval = -EIO;
  1422. spin_lock_irq(&qdio->req_q_lock);
  1423. if (zfcp_qdio_sbal_get(qdio))
  1424. goto out;
  1425. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1426. SBAL_SFLAGS0_TYPE_READ,
  1427. qdio->adapter->pool.erp_req);
  1428. if (IS_ERR(req)) {
  1429. retval = PTR_ERR(req);
  1430. goto out;
  1431. }
  1432. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1433. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1434. req->handler = zfcp_fsf_close_wka_port_handler;
  1435. req->data = wka_port;
  1436. req->qtcb->header.port_handle = wka_port->handle;
  1437. req_id = req->req_id;
  1438. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1439. retval = zfcp_fsf_req_send(req);
  1440. if (retval)
  1441. zfcp_fsf_req_free(req);
  1442. out:
  1443. spin_unlock_irq(&qdio->req_q_lock);
  1444. if (!retval)
  1445. zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req_id);
  1446. return retval;
  1447. }
  1448. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1449. {
  1450. struct zfcp_port *port = req->data;
  1451. struct fsf_qtcb_header *header = &req->qtcb->header;
  1452. struct scsi_device *sdev;
  1453. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1454. return;
  1455. switch (header->fsf_status) {
  1456. case FSF_PORT_HANDLE_NOT_VALID:
  1457. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1458. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1459. break;
  1460. case FSF_PORT_BOXED:
  1461. /* can't use generic zfcp_erp_modify_port_status because
  1462. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1463. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1464. shost_for_each_device(sdev, port->adapter->scsi_host)
  1465. if (sdev_to_zfcp(sdev)->port == port)
  1466. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1467. &sdev_to_zfcp(sdev)->status);
  1468. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1469. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1470. "fscpph2");
  1471. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1472. break;
  1473. case FSF_ADAPTER_STATUS_AVAILABLE:
  1474. switch (header->fsf_status_qual.word[0]) {
  1475. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1476. /* fall through */
  1477. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1478. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1479. break;
  1480. }
  1481. break;
  1482. case FSF_GOOD:
  1483. /* can't use generic zfcp_erp_modify_port_status because
  1484. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1485. */
  1486. atomic_andnot(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1487. shost_for_each_device(sdev, port->adapter->scsi_host)
  1488. if (sdev_to_zfcp(sdev)->port == port)
  1489. atomic_andnot(ZFCP_STATUS_COMMON_OPEN,
  1490. &sdev_to_zfcp(sdev)->status);
  1491. break;
  1492. }
  1493. }
  1494. /**
  1495. * zfcp_fsf_close_physical_port - close physical port
  1496. * @erp_action: pointer to struct zfcp_erp_action
  1497. * Returns: 0 on success
  1498. */
  1499. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1500. {
  1501. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1502. struct zfcp_fsf_req *req;
  1503. int retval = -EIO;
  1504. spin_lock_irq(&qdio->req_q_lock);
  1505. if (zfcp_qdio_sbal_get(qdio))
  1506. goto out;
  1507. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1508. SBAL_SFLAGS0_TYPE_READ,
  1509. qdio->adapter->pool.erp_req);
  1510. if (IS_ERR(req)) {
  1511. retval = PTR_ERR(req);
  1512. goto out;
  1513. }
  1514. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1515. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1516. req->data = erp_action->port;
  1517. req->qtcb->header.port_handle = erp_action->port->handle;
  1518. req->erp_action = erp_action;
  1519. req->handler = zfcp_fsf_close_physical_port_handler;
  1520. erp_action->fsf_req_id = req->req_id;
  1521. zfcp_fsf_start_erp_timer(req);
  1522. retval = zfcp_fsf_req_send(req);
  1523. if (retval) {
  1524. zfcp_fsf_req_free(req);
  1525. erp_action->fsf_req_id = 0;
  1526. }
  1527. out:
  1528. spin_unlock_irq(&qdio->req_q_lock);
  1529. return retval;
  1530. }
  1531. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1532. {
  1533. struct zfcp_adapter *adapter = req->adapter;
  1534. struct scsi_device *sdev = req->data;
  1535. struct zfcp_scsi_dev *zfcp_sdev;
  1536. struct fsf_qtcb_header *header = &req->qtcb->header;
  1537. union fsf_status_qual *qual = &header->fsf_status_qual;
  1538. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1539. return;
  1540. zfcp_sdev = sdev_to_zfcp(sdev);
  1541. atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1542. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1543. &zfcp_sdev->status);
  1544. switch (header->fsf_status) {
  1545. case FSF_PORT_HANDLE_NOT_VALID:
  1546. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1547. /* fall through */
  1548. case FSF_LUN_ALREADY_OPEN:
  1549. break;
  1550. case FSF_PORT_BOXED:
  1551. zfcp_erp_set_port_status(zfcp_sdev->port,
  1552. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1553. zfcp_erp_port_reopen(zfcp_sdev->port,
  1554. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1555. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1556. break;
  1557. case FSF_LUN_SHARING_VIOLATION:
  1558. if (qual->word[0])
  1559. dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
  1560. "LUN 0x%Lx on port 0x%Lx is already in "
  1561. "use by CSS%d, MIF Image ID %x\n",
  1562. zfcp_scsi_dev_lun(sdev),
  1563. (unsigned long long)zfcp_sdev->port->wwpn,
  1564. qual->fsf_queue_designator.cssid,
  1565. qual->fsf_queue_designator.hla);
  1566. zfcp_erp_set_lun_status(sdev,
  1567. ZFCP_STATUS_COMMON_ERP_FAILED |
  1568. ZFCP_STATUS_COMMON_ACCESS_DENIED);
  1569. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1570. break;
  1571. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1572. dev_warn(&adapter->ccw_device->dev,
  1573. "No handle is available for LUN "
  1574. "0x%016Lx on port 0x%016Lx\n",
  1575. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1576. (unsigned long long)zfcp_sdev->port->wwpn);
  1577. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1578. /* fall through */
  1579. case FSF_INVALID_COMMAND_OPTION:
  1580. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1581. break;
  1582. case FSF_ADAPTER_STATUS_AVAILABLE:
  1583. switch (header->fsf_status_qual.word[0]) {
  1584. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1585. zfcp_fc_test_link(zfcp_sdev->port);
  1586. /* fall through */
  1587. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1588. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1589. break;
  1590. }
  1591. break;
  1592. case FSF_GOOD:
  1593. zfcp_sdev->lun_handle = header->lun_handle;
  1594. atomic_or(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1595. break;
  1596. }
  1597. }
  1598. /**
  1599. * zfcp_fsf_open_lun - open LUN
  1600. * @erp_action: pointer to struct zfcp_erp_action
  1601. * Returns: 0 on success, error otherwise
  1602. */
  1603. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1604. {
  1605. struct zfcp_adapter *adapter = erp_action->adapter;
  1606. struct zfcp_qdio *qdio = adapter->qdio;
  1607. struct zfcp_fsf_req *req;
  1608. int retval = -EIO;
  1609. spin_lock_irq(&qdio->req_q_lock);
  1610. if (zfcp_qdio_sbal_get(qdio))
  1611. goto out;
  1612. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1613. SBAL_SFLAGS0_TYPE_READ,
  1614. adapter->pool.erp_req);
  1615. if (IS_ERR(req)) {
  1616. retval = PTR_ERR(req);
  1617. goto out;
  1618. }
  1619. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1620. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1621. req->qtcb->header.port_handle = erp_action->port->handle;
  1622. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1623. req->handler = zfcp_fsf_open_lun_handler;
  1624. req->data = erp_action->sdev;
  1625. req->erp_action = erp_action;
  1626. erp_action->fsf_req_id = req->req_id;
  1627. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1628. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1629. zfcp_fsf_start_erp_timer(req);
  1630. retval = zfcp_fsf_req_send(req);
  1631. if (retval) {
  1632. zfcp_fsf_req_free(req);
  1633. erp_action->fsf_req_id = 0;
  1634. }
  1635. out:
  1636. spin_unlock_irq(&qdio->req_q_lock);
  1637. return retval;
  1638. }
  1639. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1640. {
  1641. struct scsi_device *sdev = req->data;
  1642. struct zfcp_scsi_dev *zfcp_sdev;
  1643. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1644. return;
  1645. zfcp_sdev = sdev_to_zfcp(sdev);
  1646. switch (req->qtcb->header.fsf_status) {
  1647. case FSF_PORT_HANDLE_NOT_VALID:
  1648. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1649. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1650. break;
  1651. case FSF_LUN_HANDLE_NOT_VALID:
  1652. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1653. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1654. break;
  1655. case FSF_PORT_BOXED:
  1656. zfcp_erp_set_port_status(zfcp_sdev->port,
  1657. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1658. zfcp_erp_port_reopen(zfcp_sdev->port,
  1659. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1660. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1661. break;
  1662. case FSF_ADAPTER_STATUS_AVAILABLE:
  1663. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1664. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1665. zfcp_fc_test_link(zfcp_sdev->port);
  1666. /* fall through */
  1667. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1668. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1669. break;
  1670. }
  1671. break;
  1672. case FSF_GOOD:
  1673. atomic_andnot(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1674. break;
  1675. }
  1676. }
  1677. /**
  1678. * zfcp_fsf_close_LUN - close LUN
  1679. * @erp_action: pointer to erp_action triggering the "close LUN"
  1680. * Returns: 0 on success, error otherwise
  1681. */
  1682. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1683. {
  1684. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1685. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1686. struct zfcp_fsf_req *req;
  1687. int retval = -EIO;
  1688. spin_lock_irq(&qdio->req_q_lock);
  1689. if (zfcp_qdio_sbal_get(qdio))
  1690. goto out;
  1691. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1692. SBAL_SFLAGS0_TYPE_READ,
  1693. qdio->adapter->pool.erp_req);
  1694. if (IS_ERR(req)) {
  1695. retval = PTR_ERR(req);
  1696. goto out;
  1697. }
  1698. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1699. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1700. req->qtcb->header.port_handle = erp_action->port->handle;
  1701. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1702. req->handler = zfcp_fsf_close_lun_handler;
  1703. req->data = erp_action->sdev;
  1704. req->erp_action = erp_action;
  1705. erp_action->fsf_req_id = req->req_id;
  1706. zfcp_fsf_start_erp_timer(req);
  1707. retval = zfcp_fsf_req_send(req);
  1708. if (retval) {
  1709. zfcp_fsf_req_free(req);
  1710. erp_action->fsf_req_id = 0;
  1711. }
  1712. out:
  1713. spin_unlock_irq(&qdio->req_q_lock);
  1714. return retval;
  1715. }
  1716. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1717. {
  1718. lat_rec->sum += lat;
  1719. lat_rec->min = min(lat_rec->min, lat);
  1720. lat_rec->max = max(lat_rec->max, lat);
  1721. }
  1722. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1723. {
  1724. struct fsf_qual_latency_info *lat_in;
  1725. struct latency_cont *lat = NULL;
  1726. struct zfcp_scsi_dev *zfcp_sdev;
  1727. struct zfcp_blk_drv_data blktrc;
  1728. int ticks = req->adapter->timer_ticks;
  1729. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1730. blktrc.flags = 0;
  1731. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1732. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1733. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1734. blktrc.inb_usage = 0;
  1735. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1736. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1737. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1738. zfcp_sdev = sdev_to_zfcp(scsi->device);
  1739. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1740. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1741. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1742. switch (req->qtcb->bottom.io.data_direction) {
  1743. case FSF_DATADIR_DIF_READ_STRIP:
  1744. case FSF_DATADIR_DIF_READ_CONVERT:
  1745. case FSF_DATADIR_READ:
  1746. lat = &zfcp_sdev->latencies.read;
  1747. break;
  1748. case FSF_DATADIR_DIF_WRITE_INSERT:
  1749. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1750. case FSF_DATADIR_WRITE:
  1751. lat = &zfcp_sdev->latencies.write;
  1752. break;
  1753. case FSF_DATADIR_CMND:
  1754. lat = &zfcp_sdev->latencies.cmd;
  1755. break;
  1756. }
  1757. if (lat) {
  1758. spin_lock(&zfcp_sdev->latencies.lock);
  1759. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1760. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1761. lat->counter++;
  1762. spin_unlock(&zfcp_sdev->latencies.lock);
  1763. }
  1764. }
  1765. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1766. sizeof(blktrc));
  1767. }
  1768. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1769. {
  1770. struct scsi_cmnd *scmnd = req->data;
  1771. struct scsi_device *sdev = scmnd->device;
  1772. struct zfcp_scsi_dev *zfcp_sdev;
  1773. struct fsf_qtcb_header *header = &req->qtcb->header;
  1774. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1775. return;
  1776. zfcp_sdev = sdev_to_zfcp(sdev);
  1777. switch (header->fsf_status) {
  1778. case FSF_HANDLE_MISMATCH:
  1779. case FSF_PORT_HANDLE_NOT_VALID:
  1780. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1781. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1782. break;
  1783. case FSF_FCPLUN_NOT_VALID:
  1784. case FSF_LUN_HANDLE_NOT_VALID:
  1785. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1786. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1787. break;
  1788. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1789. zfcp_fsf_class_not_supp(req);
  1790. break;
  1791. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1792. dev_err(&req->adapter->ccw_device->dev,
  1793. "Incorrect direction %d, LUN 0x%016Lx on port "
  1794. "0x%016Lx closed\n",
  1795. req->qtcb->bottom.io.data_direction,
  1796. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1797. (unsigned long long)zfcp_sdev->port->wwpn);
  1798. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1799. "fssfch3");
  1800. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1801. break;
  1802. case FSF_CMND_LENGTH_NOT_VALID:
  1803. dev_err(&req->adapter->ccw_device->dev,
  1804. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1805. "port 0x%016Lx closed\n",
  1806. req->qtcb->bottom.io.fcp_cmnd_length,
  1807. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1808. (unsigned long long)zfcp_sdev->port->wwpn);
  1809. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1810. "fssfch4");
  1811. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1812. break;
  1813. case FSF_PORT_BOXED:
  1814. zfcp_erp_set_port_status(zfcp_sdev->port,
  1815. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1816. zfcp_erp_port_reopen(zfcp_sdev->port,
  1817. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1818. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1819. break;
  1820. case FSF_LUN_BOXED:
  1821. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1822. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1823. "fssfch6");
  1824. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1825. break;
  1826. case FSF_ADAPTER_STATUS_AVAILABLE:
  1827. if (header->fsf_status_qual.word[0] ==
  1828. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1829. zfcp_fc_test_link(zfcp_sdev->port);
  1830. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1831. break;
  1832. }
  1833. }
  1834. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1835. {
  1836. struct scsi_cmnd *scpnt;
  1837. struct fcp_resp_with_ext *fcp_rsp;
  1838. unsigned long flags;
  1839. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1840. scpnt = req->data;
  1841. if (unlikely(!scpnt)) {
  1842. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1843. return;
  1844. }
  1845. zfcp_fsf_fcp_handler_common(req);
  1846. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1847. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1848. goto skip_fsfstatus;
  1849. }
  1850. switch (req->qtcb->header.fsf_status) {
  1851. case FSF_INCONSISTENT_PROT_DATA:
  1852. case FSF_INVALID_PROT_PARM:
  1853. set_host_byte(scpnt, DID_ERROR);
  1854. goto skip_fsfstatus;
  1855. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1856. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1857. goto skip_fsfstatus;
  1858. case FSF_APP_TAG_CHECK_FAILURE:
  1859. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1860. goto skip_fsfstatus;
  1861. case FSF_REF_TAG_CHECK_FAILURE:
  1862. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1863. goto skip_fsfstatus;
  1864. }
  1865. BUILD_BUG_ON(sizeof(struct fcp_resp_with_ext) > FSF_FCP_RSP_SIZE);
  1866. fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
  1867. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1868. skip_fsfstatus:
  1869. zfcp_fsf_req_trace(req, scpnt);
  1870. zfcp_dbf_scsi_result(scpnt, req);
  1871. scpnt->host_scribble = NULL;
  1872. (scpnt->scsi_done) (scpnt);
  1873. /*
  1874. * We must hold this lock until scsi_done has been called.
  1875. * Otherwise we may call scsi_done after abort regarding this
  1876. * command has completed.
  1877. * Note: scsi_done must not block!
  1878. */
  1879. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1880. }
  1881. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1882. {
  1883. switch (scsi_get_prot_op(scsi_cmnd)) {
  1884. case SCSI_PROT_NORMAL:
  1885. switch (scsi_cmnd->sc_data_direction) {
  1886. case DMA_NONE:
  1887. *data_dir = FSF_DATADIR_CMND;
  1888. break;
  1889. case DMA_FROM_DEVICE:
  1890. *data_dir = FSF_DATADIR_READ;
  1891. break;
  1892. case DMA_TO_DEVICE:
  1893. *data_dir = FSF_DATADIR_WRITE;
  1894. break;
  1895. case DMA_BIDIRECTIONAL:
  1896. return -EINVAL;
  1897. }
  1898. break;
  1899. case SCSI_PROT_READ_STRIP:
  1900. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1901. break;
  1902. case SCSI_PROT_WRITE_INSERT:
  1903. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1904. break;
  1905. case SCSI_PROT_READ_PASS:
  1906. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1907. break;
  1908. case SCSI_PROT_WRITE_PASS:
  1909. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1910. break;
  1911. default:
  1912. return -EINVAL;
  1913. }
  1914. return 0;
  1915. }
  1916. /**
  1917. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1918. * @scsi_cmnd: scsi command to be sent
  1919. */
  1920. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1921. {
  1922. struct zfcp_fsf_req *req;
  1923. struct fcp_cmnd *fcp_cmnd;
  1924. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1925. int retval = -EIO;
  1926. struct scsi_device *sdev = scsi_cmnd->device;
  1927. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1928. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1929. struct zfcp_qdio *qdio = adapter->qdio;
  1930. struct fsf_qtcb_bottom_io *io;
  1931. unsigned long flags;
  1932. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1933. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1934. return -EBUSY;
  1935. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1936. if (atomic_read(&qdio->req_q_free) <= 0) {
  1937. atomic_inc(&qdio->req_q_full);
  1938. goto out;
  1939. }
  1940. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1941. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1942. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1943. sbtype, adapter->pool.scsi_req);
  1944. if (IS_ERR(req)) {
  1945. retval = PTR_ERR(req);
  1946. goto out;
  1947. }
  1948. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1949. io = &req->qtcb->bottom.io;
  1950. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1951. req->data = scsi_cmnd;
  1952. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1953. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1954. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1955. io->service_class = FSF_CLASS_3;
  1956. io->fcp_cmnd_length = FCP_CMND_LEN;
  1957. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1958. io->data_block_length = scsi_cmnd->device->sector_size;
  1959. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1960. }
  1961. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1962. goto failed_scsi_cmnd;
  1963. BUILD_BUG_ON(sizeof(struct fcp_cmnd) > FSF_FCP_CMND_SIZE);
  1964. fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
  1965. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1966. if ((scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) &&
  1967. scsi_prot_sg_count(scsi_cmnd)) {
  1968. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1969. scsi_prot_sg_count(scsi_cmnd));
  1970. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1971. scsi_prot_sglist(scsi_cmnd));
  1972. if (retval)
  1973. goto failed_scsi_cmnd;
  1974. io->prot_data_length = zfcp_qdio_real_bytes(
  1975. scsi_prot_sglist(scsi_cmnd));
  1976. }
  1977. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1978. scsi_sglist(scsi_cmnd));
  1979. if (unlikely(retval))
  1980. goto failed_scsi_cmnd;
  1981. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1982. if (zfcp_adapter_multi_buffer_active(adapter))
  1983. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1984. retval = zfcp_fsf_req_send(req);
  1985. if (unlikely(retval))
  1986. goto failed_scsi_cmnd;
  1987. goto out;
  1988. failed_scsi_cmnd:
  1989. zfcp_fsf_req_free(req);
  1990. scsi_cmnd->host_scribble = NULL;
  1991. out:
  1992. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1993. return retval;
  1994. }
  1995. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1996. {
  1997. struct fcp_resp_with_ext *fcp_rsp;
  1998. struct fcp_resp_rsp_info *rsp_info;
  1999. zfcp_fsf_fcp_handler_common(req);
  2000. fcp_rsp = &req->qtcb->bottom.io.fcp_rsp.iu;
  2001. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  2002. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  2003. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  2004. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  2005. }
  2006. /**
  2007. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  2008. * @scmnd: SCSI command to send the task management command for
  2009. * @tm_flags: unsigned byte for task management flags
  2010. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2011. */
  2012. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  2013. u8 tm_flags)
  2014. {
  2015. struct zfcp_fsf_req *req = NULL;
  2016. struct fcp_cmnd *fcp_cmnd;
  2017. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  2018. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  2019. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  2020. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2021. return NULL;
  2022. spin_lock_irq(&qdio->req_q_lock);
  2023. if (zfcp_qdio_sbal_get(qdio))
  2024. goto out;
  2025. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2026. SBAL_SFLAGS0_TYPE_WRITE,
  2027. qdio->adapter->pool.scsi_req);
  2028. if (IS_ERR(req)) {
  2029. req = NULL;
  2030. goto out;
  2031. }
  2032. req->data = scmnd;
  2033. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2034. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2035. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2036. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2037. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2038. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2039. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2040. fcp_cmnd = &req->qtcb->bottom.io.fcp_cmnd.iu;
  2041. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2042. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2043. if (!zfcp_fsf_req_send(req))
  2044. goto out;
  2045. zfcp_fsf_req_free(req);
  2046. req = NULL;
  2047. out:
  2048. spin_unlock_irq(&qdio->req_q_lock);
  2049. return req;
  2050. }
  2051. /**
  2052. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2053. * @adapter: pointer to struct zfcp_adapter
  2054. * @sbal_idx: response queue index of SBAL to be processed
  2055. */
  2056. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2057. {
  2058. struct zfcp_adapter *adapter = qdio->adapter;
  2059. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2060. struct qdio_buffer_element *sbale;
  2061. struct zfcp_fsf_req *fsf_req;
  2062. unsigned long req_id;
  2063. int idx;
  2064. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2065. sbale = &sbal->element[idx];
  2066. req_id = (unsigned long) sbale->addr;
  2067. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2068. if (!fsf_req) {
  2069. /*
  2070. * Unknown request means that we have potentially memory
  2071. * corruption and must stop the machine immediately.
  2072. */
  2073. zfcp_qdio_siosl(adapter);
  2074. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2075. req_id, dev_name(&adapter->ccw_device->dev));
  2076. }
  2077. zfcp_fsf_req_complete(fsf_req);
  2078. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2079. break;
  2080. }
  2081. }