zfcp_fsf.c 67 KB

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