zfcp_fsf.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corp. 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_4", 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. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  399. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  400. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  401. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  402. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  403. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  404. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  405. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  406. {
  407. u32 fdmi_speed = 0;
  408. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  409. fdmi_speed |= FC_PORTSPEED_1GBIT;
  410. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  411. fdmi_speed |= FC_PORTSPEED_2GBIT;
  412. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  413. fdmi_speed |= FC_PORTSPEED_4GBIT;
  414. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  415. fdmi_speed |= FC_PORTSPEED_10GBIT;
  416. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  417. fdmi_speed |= FC_PORTSPEED_8GBIT;
  418. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  419. fdmi_speed |= FC_PORTSPEED_16GBIT;
  420. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  421. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  422. return fdmi_speed;
  423. }
  424. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  425. {
  426. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  427. struct zfcp_adapter *adapter = req->adapter;
  428. struct Scsi_Host *shost = adapter->scsi_host;
  429. struct fc_els_flogi *nsp, *plogi;
  430. /* adjust pointers for missing command code */
  431. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  432. - sizeof(u32));
  433. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  434. - sizeof(u32));
  435. if (req->data)
  436. memcpy(req->data, bottom, sizeof(*bottom));
  437. fc_host_port_name(shost) = nsp->fl_wwpn;
  438. fc_host_node_name(shost) = nsp->fl_wwnn;
  439. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  440. fc_host_speed(shost) =
  441. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  442. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  443. adapter->hydra_version = bottom->adapter_type;
  444. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  445. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  446. (u16)FSF_STATUS_READS_RECOM);
  447. if (fc_host_permanent_port_name(shost) == -1)
  448. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  449. switch (bottom->fc_topology) {
  450. case FSF_TOPO_P2P:
  451. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  452. adapter->peer_wwpn = plogi->fl_wwpn;
  453. adapter->peer_wwnn = plogi->fl_wwnn;
  454. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  455. break;
  456. case FSF_TOPO_FABRIC:
  457. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  458. break;
  459. case FSF_TOPO_AL:
  460. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  461. /* fall through */
  462. default:
  463. dev_err(&adapter->ccw_device->dev,
  464. "Unknown or unsupported arbitrated loop "
  465. "fibre channel topology detected\n");
  466. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  467. return -EIO;
  468. }
  469. zfcp_scsi_set_prot(adapter);
  470. return 0;
  471. }
  472. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  473. {
  474. struct zfcp_adapter *adapter = req->adapter;
  475. struct fsf_qtcb *qtcb = req->qtcb;
  476. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  477. struct Scsi_Host *shost = adapter->scsi_host;
  478. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  479. return;
  480. adapter->fsf_lic_version = bottom->lic_version;
  481. adapter->adapter_features = bottom->adapter_features;
  482. adapter->connection_features = bottom->connection_features;
  483. adapter->peer_wwpn = 0;
  484. adapter->peer_wwnn = 0;
  485. adapter->peer_d_id = 0;
  486. switch (qtcb->header.fsf_status) {
  487. case FSF_GOOD:
  488. if (zfcp_fsf_exchange_config_evaluate(req))
  489. return;
  490. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  491. dev_err(&adapter->ccw_device->dev,
  492. "FCP adapter maximum QTCB size (%d bytes) "
  493. "is too small\n",
  494. bottom->max_qtcb_size);
  495. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  496. return;
  497. }
  498. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  499. &adapter->status);
  500. break;
  501. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  502. fc_host_node_name(shost) = 0;
  503. fc_host_port_name(shost) = 0;
  504. fc_host_port_id(shost) = 0;
  505. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  506. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  507. adapter->hydra_version = 0;
  508. zfcp_fsf_link_down_info_eval(req,
  509. &qtcb->header.fsf_status_qual.link_down_info);
  510. break;
  511. default:
  512. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  513. return;
  514. }
  515. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  516. adapter->hardware_version = bottom->hardware_version;
  517. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  518. min(FC_SERIAL_NUMBER_SIZE, 17));
  519. EBCASC(fc_host_serial_number(shost),
  520. min(FC_SERIAL_NUMBER_SIZE, 17));
  521. }
  522. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  523. dev_err(&adapter->ccw_device->dev,
  524. "The FCP adapter only supports newer "
  525. "control block versions\n");
  526. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  527. return;
  528. }
  529. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  530. dev_err(&adapter->ccw_device->dev,
  531. "The FCP adapter only supports older "
  532. "control block versions\n");
  533. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  534. }
  535. }
  536. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  537. {
  538. struct zfcp_adapter *adapter = req->adapter;
  539. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  540. struct Scsi_Host *shost = adapter->scsi_host;
  541. if (req->data)
  542. memcpy(req->data, bottom, sizeof(*bottom));
  543. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  544. fc_host_permanent_port_name(shost) = bottom->wwpn;
  545. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  546. } else
  547. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  548. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  549. fc_host_supported_speeds(shost) =
  550. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  551. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  552. FC_FC4_LIST_SIZE);
  553. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  554. FC_FC4_LIST_SIZE);
  555. }
  556. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  557. {
  558. struct fsf_qtcb *qtcb = req->qtcb;
  559. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  560. return;
  561. switch (qtcb->header.fsf_status) {
  562. case FSF_GOOD:
  563. zfcp_fsf_exchange_port_evaluate(req);
  564. break;
  565. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  566. zfcp_fsf_exchange_port_evaluate(req);
  567. zfcp_fsf_link_down_info_eval(req,
  568. &qtcb->header.fsf_status_qual.link_down_info);
  569. break;
  570. }
  571. }
  572. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  573. {
  574. struct zfcp_fsf_req *req;
  575. if (likely(pool))
  576. req = mempool_alloc(pool, GFP_ATOMIC);
  577. else
  578. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  579. if (unlikely(!req))
  580. return NULL;
  581. memset(req, 0, sizeof(*req));
  582. req->pool = pool;
  583. return req;
  584. }
  585. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  586. {
  587. struct fsf_qtcb *qtcb;
  588. if (likely(pool))
  589. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  590. else
  591. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  592. if (unlikely(!qtcb))
  593. return NULL;
  594. memset(qtcb, 0, sizeof(*qtcb));
  595. return qtcb;
  596. }
  597. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  598. u32 fsf_cmd, u8 sbtype,
  599. mempool_t *pool)
  600. {
  601. struct zfcp_adapter *adapter = qdio->adapter;
  602. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  603. if (unlikely(!req))
  604. return ERR_PTR(-ENOMEM);
  605. if (adapter->req_no == 0)
  606. adapter->req_no++;
  607. INIT_LIST_HEAD(&req->list);
  608. init_timer(&req->timer);
  609. init_completion(&req->completion);
  610. req->adapter = adapter;
  611. req->fsf_command = fsf_cmd;
  612. req->req_id = adapter->req_no;
  613. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  614. if (likely(pool))
  615. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  616. else
  617. req->qtcb = zfcp_qtcb_alloc(NULL);
  618. if (unlikely(!req->qtcb)) {
  619. zfcp_fsf_req_free(req);
  620. return ERR_PTR(-ENOMEM);
  621. }
  622. req->seq_no = adapter->fsf_req_seq_no;
  623. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  624. req->qtcb->prefix.req_id = req->req_id;
  625. req->qtcb->prefix.ulp_info = 26;
  626. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  627. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  628. req->qtcb->header.req_handle = req->req_id;
  629. req->qtcb->header.fsf_command = req->fsf_command;
  630. }
  631. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  632. req->qtcb, sizeof(struct fsf_qtcb));
  633. return req;
  634. }
  635. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  636. {
  637. struct zfcp_adapter *adapter = req->adapter;
  638. struct zfcp_qdio *qdio = adapter->qdio;
  639. int with_qtcb = (req->qtcb != NULL);
  640. int req_id = req->req_id;
  641. zfcp_reqlist_add(adapter->req_list, req);
  642. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  643. req->issued = get_clock();
  644. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  645. del_timer(&req->timer);
  646. /* lookup request again, list might have changed */
  647. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  648. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  649. return -EIO;
  650. }
  651. /* Don't increase for unsolicited status */
  652. if (with_qtcb)
  653. adapter->fsf_req_seq_no++;
  654. adapter->req_no++;
  655. return 0;
  656. }
  657. /**
  658. * zfcp_fsf_status_read - send status read request
  659. * @adapter: pointer to struct zfcp_adapter
  660. * @req_flags: request flags
  661. * Returns: 0 on success, ERROR otherwise
  662. */
  663. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  664. {
  665. struct zfcp_adapter *adapter = qdio->adapter;
  666. struct zfcp_fsf_req *req;
  667. struct fsf_status_read_buffer *sr_buf;
  668. struct page *page;
  669. int retval = -EIO;
  670. spin_lock_irq(&qdio->req_q_lock);
  671. if (zfcp_qdio_sbal_get(qdio))
  672. goto out;
  673. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  674. adapter->pool.status_read_req);
  675. if (IS_ERR(req)) {
  676. retval = PTR_ERR(req);
  677. goto out;
  678. }
  679. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  680. if (!page) {
  681. retval = -ENOMEM;
  682. goto failed_buf;
  683. }
  684. sr_buf = page_address(page);
  685. memset(sr_buf, 0, sizeof(*sr_buf));
  686. req->data = sr_buf;
  687. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  688. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  689. retval = zfcp_fsf_req_send(req);
  690. if (retval)
  691. goto failed_req_send;
  692. goto out;
  693. failed_req_send:
  694. req->data = NULL;
  695. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  696. failed_buf:
  697. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  698. zfcp_fsf_req_free(req);
  699. out:
  700. spin_unlock_irq(&qdio->req_q_lock);
  701. return retval;
  702. }
  703. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  704. {
  705. struct scsi_device *sdev = req->data;
  706. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  707. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  708. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  709. return;
  710. switch (req->qtcb->header.fsf_status) {
  711. case FSF_PORT_HANDLE_NOT_VALID:
  712. if (fsq->word[0] == fsq->word[1]) {
  713. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  714. "fsafch1");
  715. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  716. }
  717. break;
  718. case FSF_LUN_HANDLE_NOT_VALID:
  719. if (fsq->word[0] == fsq->word[1]) {
  720. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  721. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  722. }
  723. break;
  724. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  725. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  726. break;
  727. case FSF_PORT_BOXED:
  728. zfcp_erp_set_port_status(zfcp_sdev->port,
  729. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  730. zfcp_erp_port_reopen(zfcp_sdev->port,
  731. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  732. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  733. break;
  734. case FSF_LUN_BOXED:
  735. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  736. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  737. "fsafch4");
  738. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  739. break;
  740. case FSF_ADAPTER_STATUS_AVAILABLE:
  741. switch (fsq->word[0]) {
  742. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  743. zfcp_fc_test_link(zfcp_sdev->port);
  744. /* fall through */
  745. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  746. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  747. break;
  748. }
  749. break;
  750. case FSF_GOOD:
  751. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  752. break;
  753. }
  754. }
  755. /**
  756. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  757. * @scmnd: The SCSI command to abort
  758. * Returns: pointer to struct zfcp_fsf_req
  759. */
  760. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  761. {
  762. struct zfcp_fsf_req *req = NULL;
  763. struct scsi_device *sdev = scmnd->device;
  764. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  765. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  766. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  767. spin_lock_irq(&qdio->req_q_lock);
  768. if (zfcp_qdio_sbal_get(qdio))
  769. goto out;
  770. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  771. SBAL_SFLAGS0_TYPE_READ,
  772. qdio->adapter->pool.scsi_abort);
  773. if (IS_ERR(req)) {
  774. req = NULL;
  775. goto out;
  776. }
  777. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  778. ZFCP_STATUS_COMMON_UNBLOCKED)))
  779. goto out_error_free;
  780. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  781. req->data = sdev;
  782. req->handler = zfcp_fsf_abort_fcp_command_handler;
  783. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  784. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  785. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  786. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  787. if (!zfcp_fsf_req_send(req))
  788. goto out;
  789. out_error_free:
  790. zfcp_fsf_req_free(req);
  791. req = NULL;
  792. out:
  793. spin_unlock_irq(&qdio->req_q_lock);
  794. return req;
  795. }
  796. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  797. {
  798. struct zfcp_adapter *adapter = req->adapter;
  799. struct zfcp_fsf_ct_els *ct = req->data;
  800. struct fsf_qtcb_header *header = &req->qtcb->header;
  801. ct->status = -EINVAL;
  802. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  803. goto skip_fsfstatus;
  804. switch (header->fsf_status) {
  805. case FSF_GOOD:
  806. zfcp_dbf_san_res("fsscth2", req);
  807. ct->status = 0;
  808. break;
  809. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  810. zfcp_fsf_class_not_supp(req);
  811. break;
  812. case FSF_ADAPTER_STATUS_AVAILABLE:
  813. switch (header->fsf_status_qual.word[0]){
  814. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  815. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  816. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  817. break;
  818. }
  819. break;
  820. case FSF_ACCESS_DENIED:
  821. break;
  822. case FSF_PORT_BOXED:
  823. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  824. break;
  825. case FSF_PORT_HANDLE_NOT_VALID:
  826. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  827. /* fall through */
  828. case FSF_GENERIC_COMMAND_REJECTED:
  829. case FSF_PAYLOAD_SIZE_MISMATCH:
  830. case FSF_REQUEST_SIZE_TOO_LARGE:
  831. case FSF_RESPONSE_SIZE_TOO_LARGE:
  832. case FSF_SBAL_MISMATCH:
  833. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  834. break;
  835. }
  836. skip_fsfstatus:
  837. if (ct->handler)
  838. ct->handler(ct->handler_data);
  839. }
  840. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  841. struct zfcp_qdio_req *q_req,
  842. struct scatterlist *sg_req,
  843. struct scatterlist *sg_resp)
  844. {
  845. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  846. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  847. zfcp_qdio_set_sbale_last(qdio, q_req);
  848. }
  849. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  850. struct scatterlist *sg_req,
  851. struct scatterlist *sg_resp)
  852. {
  853. struct zfcp_adapter *adapter = req->adapter;
  854. struct zfcp_qdio *qdio = adapter->qdio;
  855. struct fsf_qtcb *qtcb = req->qtcb;
  856. u32 feat = adapter->adapter_features;
  857. if (zfcp_adapter_multi_buffer_active(adapter)) {
  858. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  859. return -EIO;
  860. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  861. return -EIO;
  862. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  863. zfcp_qdio_sbale_count(sg_req));
  864. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  865. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  866. return 0;
  867. }
  868. /* use single, unchained SBAL if it can hold the request */
  869. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  870. zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
  871. sg_req, sg_resp);
  872. return 0;
  873. }
  874. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
  875. return -EOPNOTSUPP;
  876. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  877. return -EIO;
  878. qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
  879. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  880. zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
  881. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  882. return -EIO;
  883. qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
  884. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  885. return 0;
  886. }
  887. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  888. struct scatterlist *sg_req,
  889. struct scatterlist *sg_resp,
  890. unsigned int timeout)
  891. {
  892. int ret;
  893. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  894. if (ret)
  895. return ret;
  896. /* common settings for ct/gs and els requests */
  897. if (timeout > 255)
  898. timeout = 255; /* max value accepted by hardware */
  899. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  900. req->qtcb->bottom.support.timeout = timeout;
  901. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  902. return 0;
  903. }
  904. /**
  905. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  906. * @ct: pointer to struct zfcp_send_ct with data for request
  907. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  908. */
  909. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  910. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  911. unsigned int timeout)
  912. {
  913. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  914. struct zfcp_fsf_req *req;
  915. int ret = -EIO;
  916. spin_lock_irq(&qdio->req_q_lock);
  917. if (zfcp_qdio_sbal_get(qdio))
  918. goto out;
  919. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  920. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  921. if (IS_ERR(req)) {
  922. ret = PTR_ERR(req);
  923. goto out;
  924. }
  925. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  926. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  927. if (ret)
  928. goto failed_send;
  929. req->handler = zfcp_fsf_send_ct_handler;
  930. req->qtcb->header.port_handle = wka_port->handle;
  931. req->data = ct;
  932. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  933. ret = zfcp_fsf_req_send(req);
  934. if (ret)
  935. goto failed_send;
  936. goto out;
  937. failed_send:
  938. zfcp_fsf_req_free(req);
  939. out:
  940. spin_unlock_irq(&qdio->req_q_lock);
  941. return ret;
  942. }
  943. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  944. {
  945. struct zfcp_fsf_ct_els *send_els = req->data;
  946. struct zfcp_port *port = send_els->port;
  947. struct fsf_qtcb_header *header = &req->qtcb->header;
  948. send_els->status = -EINVAL;
  949. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  950. goto skip_fsfstatus;
  951. switch (header->fsf_status) {
  952. case FSF_GOOD:
  953. zfcp_dbf_san_res("fsselh1", req);
  954. send_els->status = 0;
  955. break;
  956. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  957. zfcp_fsf_class_not_supp(req);
  958. break;
  959. case FSF_ADAPTER_STATUS_AVAILABLE:
  960. switch (header->fsf_status_qual.word[0]){
  961. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  962. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  963. case FSF_SQ_RETRY_IF_POSSIBLE:
  964. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  965. break;
  966. }
  967. break;
  968. case FSF_ELS_COMMAND_REJECTED:
  969. case FSF_PAYLOAD_SIZE_MISMATCH:
  970. case FSF_REQUEST_SIZE_TOO_LARGE:
  971. case FSF_RESPONSE_SIZE_TOO_LARGE:
  972. break;
  973. case FSF_ACCESS_DENIED:
  974. if (port) {
  975. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  976. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  977. }
  978. break;
  979. case FSF_SBAL_MISMATCH:
  980. /* should never occur, avoided in zfcp_fsf_send_els */
  981. /* fall through */
  982. default:
  983. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  984. break;
  985. }
  986. skip_fsfstatus:
  987. if (send_els->handler)
  988. send_els->handler(send_els->handler_data);
  989. }
  990. /**
  991. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  992. * @els: pointer to struct zfcp_send_els with data for the command
  993. */
  994. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  995. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  996. {
  997. struct zfcp_fsf_req *req;
  998. struct zfcp_qdio *qdio = adapter->qdio;
  999. int ret = -EIO;
  1000. spin_lock_irq(&qdio->req_q_lock);
  1001. if (zfcp_qdio_sbal_get(qdio))
  1002. goto out;
  1003. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1004. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1005. if (IS_ERR(req)) {
  1006. ret = PTR_ERR(req);
  1007. goto out;
  1008. }
  1009. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1010. if (!zfcp_adapter_multi_buffer_active(adapter))
  1011. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1012. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1013. if (ret)
  1014. goto failed_send;
  1015. hton24(req->qtcb->bottom.support.d_id, d_id);
  1016. req->handler = zfcp_fsf_send_els_handler;
  1017. req->data = els;
  1018. zfcp_dbf_san_req("fssels1", req, d_id);
  1019. ret = zfcp_fsf_req_send(req);
  1020. if (ret)
  1021. goto failed_send;
  1022. goto out;
  1023. failed_send:
  1024. zfcp_fsf_req_free(req);
  1025. out:
  1026. spin_unlock_irq(&qdio->req_q_lock);
  1027. return ret;
  1028. }
  1029. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1030. {
  1031. struct zfcp_fsf_req *req;
  1032. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1033. int retval = -EIO;
  1034. spin_lock_irq(&qdio->req_q_lock);
  1035. if (zfcp_qdio_sbal_get(qdio))
  1036. goto out;
  1037. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1038. SBAL_SFLAGS0_TYPE_READ,
  1039. qdio->adapter->pool.erp_req);
  1040. if (IS_ERR(req)) {
  1041. retval = PTR_ERR(req);
  1042. goto out;
  1043. }
  1044. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1045. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1046. req->qtcb->bottom.config.feature_selection =
  1047. FSF_FEATURE_CFDC |
  1048. FSF_FEATURE_LUN_SHARING |
  1049. FSF_FEATURE_NOTIFICATION_LOST |
  1050. FSF_FEATURE_UPDATE_ALERT;
  1051. req->erp_action = erp_action;
  1052. req->handler = zfcp_fsf_exchange_config_data_handler;
  1053. erp_action->fsf_req_id = req->req_id;
  1054. zfcp_fsf_start_erp_timer(req);
  1055. retval = zfcp_fsf_req_send(req);
  1056. if (retval) {
  1057. zfcp_fsf_req_free(req);
  1058. erp_action->fsf_req_id = 0;
  1059. }
  1060. out:
  1061. spin_unlock_irq(&qdio->req_q_lock);
  1062. return retval;
  1063. }
  1064. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1065. struct fsf_qtcb_bottom_config *data)
  1066. {
  1067. struct zfcp_fsf_req *req = NULL;
  1068. int retval = -EIO;
  1069. spin_lock_irq(&qdio->req_q_lock);
  1070. if (zfcp_qdio_sbal_get(qdio))
  1071. goto out_unlock;
  1072. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1073. SBAL_SFLAGS0_TYPE_READ, NULL);
  1074. if (IS_ERR(req)) {
  1075. retval = PTR_ERR(req);
  1076. goto out_unlock;
  1077. }
  1078. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1079. req->handler = zfcp_fsf_exchange_config_data_handler;
  1080. req->qtcb->bottom.config.feature_selection =
  1081. FSF_FEATURE_CFDC |
  1082. FSF_FEATURE_LUN_SHARING |
  1083. FSF_FEATURE_NOTIFICATION_LOST |
  1084. FSF_FEATURE_UPDATE_ALERT;
  1085. if (data)
  1086. req->data = data;
  1087. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1088. retval = zfcp_fsf_req_send(req);
  1089. spin_unlock_irq(&qdio->req_q_lock);
  1090. if (!retval)
  1091. wait_for_completion(&req->completion);
  1092. zfcp_fsf_req_free(req);
  1093. return retval;
  1094. out_unlock:
  1095. spin_unlock_irq(&qdio->req_q_lock);
  1096. return retval;
  1097. }
  1098. /**
  1099. * zfcp_fsf_exchange_port_data - request information about local port
  1100. * @erp_action: ERP action for the adapter for which port data is requested
  1101. * Returns: 0 on success, error otherwise
  1102. */
  1103. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1104. {
  1105. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1106. struct zfcp_fsf_req *req;
  1107. int retval = -EIO;
  1108. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1109. return -EOPNOTSUPP;
  1110. spin_lock_irq(&qdio->req_q_lock);
  1111. if (zfcp_qdio_sbal_get(qdio))
  1112. goto out;
  1113. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1114. SBAL_SFLAGS0_TYPE_READ,
  1115. qdio->adapter->pool.erp_req);
  1116. if (IS_ERR(req)) {
  1117. retval = PTR_ERR(req);
  1118. goto out;
  1119. }
  1120. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1121. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1122. req->handler = zfcp_fsf_exchange_port_data_handler;
  1123. req->erp_action = erp_action;
  1124. erp_action->fsf_req_id = req->req_id;
  1125. zfcp_fsf_start_erp_timer(req);
  1126. retval = zfcp_fsf_req_send(req);
  1127. if (retval) {
  1128. zfcp_fsf_req_free(req);
  1129. erp_action->fsf_req_id = 0;
  1130. }
  1131. out:
  1132. spin_unlock_irq(&qdio->req_q_lock);
  1133. return retval;
  1134. }
  1135. /**
  1136. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1137. * @qdio: pointer to struct zfcp_qdio
  1138. * @data: pointer to struct fsf_qtcb_bottom_port
  1139. * Returns: 0 on success, error otherwise
  1140. */
  1141. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1142. struct fsf_qtcb_bottom_port *data)
  1143. {
  1144. struct zfcp_fsf_req *req = NULL;
  1145. int retval = -EIO;
  1146. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1147. return -EOPNOTSUPP;
  1148. spin_lock_irq(&qdio->req_q_lock);
  1149. if (zfcp_qdio_sbal_get(qdio))
  1150. goto out_unlock;
  1151. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1152. SBAL_SFLAGS0_TYPE_READ, NULL);
  1153. if (IS_ERR(req)) {
  1154. retval = PTR_ERR(req);
  1155. goto out_unlock;
  1156. }
  1157. if (data)
  1158. req->data = data;
  1159. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1160. req->handler = zfcp_fsf_exchange_port_data_handler;
  1161. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1162. retval = zfcp_fsf_req_send(req);
  1163. spin_unlock_irq(&qdio->req_q_lock);
  1164. if (!retval)
  1165. wait_for_completion(&req->completion);
  1166. zfcp_fsf_req_free(req);
  1167. return retval;
  1168. out_unlock:
  1169. spin_unlock_irq(&qdio->req_q_lock);
  1170. return retval;
  1171. }
  1172. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1173. {
  1174. struct zfcp_port *port = req->data;
  1175. struct fsf_qtcb_header *header = &req->qtcb->header;
  1176. struct fc_els_flogi *plogi;
  1177. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1178. goto out;
  1179. switch (header->fsf_status) {
  1180. case FSF_PORT_ALREADY_OPEN:
  1181. break;
  1182. case FSF_ACCESS_DENIED:
  1183. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1184. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1185. break;
  1186. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1187. dev_warn(&req->adapter->ccw_device->dev,
  1188. "Not enough FCP adapter resources to open "
  1189. "remote port 0x%016Lx\n",
  1190. (unsigned long long)port->wwpn);
  1191. zfcp_erp_set_port_status(port,
  1192. ZFCP_STATUS_COMMON_ERP_FAILED);
  1193. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1194. break;
  1195. case FSF_ADAPTER_STATUS_AVAILABLE:
  1196. switch (header->fsf_status_qual.word[0]) {
  1197. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1198. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1199. case FSF_SQ_NO_RETRY_POSSIBLE:
  1200. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1201. break;
  1202. }
  1203. break;
  1204. case FSF_GOOD:
  1205. port->handle = header->port_handle;
  1206. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1207. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1208. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1209. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1210. &port->status);
  1211. /* check whether D_ID has changed during open */
  1212. /*
  1213. * FIXME: This check is not airtight, as the FCP channel does
  1214. * not monitor closures of target port connections caused on
  1215. * the remote side. Thus, they might miss out on invalidating
  1216. * locally cached WWPNs (and other N_Port parameters) of gone
  1217. * target ports. So, our heroic attempt to make things safe
  1218. * could be undermined by 'open port' response data tagged with
  1219. * obsolete WWPNs. Another reason to monitor potential
  1220. * connection closures ourself at least (by interpreting
  1221. * incoming ELS' and unsolicited status). It just crosses my
  1222. * mind that one should be able to cross-check by means of
  1223. * another GID_PN straight after a port has been opened.
  1224. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1225. */
  1226. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1227. if (req->qtcb->bottom.support.els1_length >=
  1228. FSF_PLOGI_MIN_LEN)
  1229. zfcp_fc_plogi_evaluate(port, plogi);
  1230. break;
  1231. case FSF_UNKNOWN_OP_SUBTYPE:
  1232. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1233. break;
  1234. }
  1235. out:
  1236. put_device(&port->dev);
  1237. }
  1238. /**
  1239. * zfcp_fsf_open_port - create and send open port request
  1240. * @erp_action: pointer to struct zfcp_erp_action
  1241. * Returns: 0 on success, error otherwise
  1242. */
  1243. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1244. {
  1245. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1246. struct zfcp_port *port = erp_action->port;
  1247. struct zfcp_fsf_req *req;
  1248. int retval = -EIO;
  1249. spin_lock_irq(&qdio->req_q_lock);
  1250. if (zfcp_qdio_sbal_get(qdio))
  1251. goto out;
  1252. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1253. SBAL_SFLAGS0_TYPE_READ,
  1254. qdio->adapter->pool.erp_req);
  1255. if (IS_ERR(req)) {
  1256. retval = PTR_ERR(req);
  1257. goto out;
  1258. }
  1259. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1260. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1261. req->handler = zfcp_fsf_open_port_handler;
  1262. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1263. req->data = port;
  1264. req->erp_action = erp_action;
  1265. erp_action->fsf_req_id = req->req_id;
  1266. get_device(&port->dev);
  1267. zfcp_fsf_start_erp_timer(req);
  1268. retval = zfcp_fsf_req_send(req);
  1269. if (retval) {
  1270. zfcp_fsf_req_free(req);
  1271. erp_action->fsf_req_id = 0;
  1272. put_device(&port->dev);
  1273. }
  1274. out:
  1275. spin_unlock_irq(&qdio->req_q_lock);
  1276. return retval;
  1277. }
  1278. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1279. {
  1280. struct zfcp_port *port = req->data;
  1281. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1282. return;
  1283. switch (req->qtcb->header.fsf_status) {
  1284. case FSF_PORT_HANDLE_NOT_VALID:
  1285. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1286. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1287. break;
  1288. case FSF_ADAPTER_STATUS_AVAILABLE:
  1289. break;
  1290. case FSF_GOOD:
  1291. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1292. break;
  1293. }
  1294. }
  1295. /**
  1296. * zfcp_fsf_close_port - create and send close port request
  1297. * @erp_action: pointer to struct zfcp_erp_action
  1298. * Returns: 0 on success, error otherwise
  1299. */
  1300. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1301. {
  1302. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1303. struct zfcp_fsf_req *req;
  1304. int retval = -EIO;
  1305. spin_lock_irq(&qdio->req_q_lock);
  1306. if (zfcp_qdio_sbal_get(qdio))
  1307. goto out;
  1308. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1309. SBAL_SFLAGS0_TYPE_READ,
  1310. qdio->adapter->pool.erp_req);
  1311. if (IS_ERR(req)) {
  1312. retval = PTR_ERR(req);
  1313. goto out;
  1314. }
  1315. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1316. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1317. req->handler = zfcp_fsf_close_port_handler;
  1318. req->data = erp_action->port;
  1319. req->erp_action = erp_action;
  1320. req->qtcb->header.port_handle = erp_action->port->handle;
  1321. erp_action->fsf_req_id = req->req_id;
  1322. zfcp_fsf_start_erp_timer(req);
  1323. retval = zfcp_fsf_req_send(req);
  1324. if (retval) {
  1325. zfcp_fsf_req_free(req);
  1326. erp_action->fsf_req_id = 0;
  1327. }
  1328. out:
  1329. spin_unlock_irq(&qdio->req_q_lock);
  1330. return retval;
  1331. }
  1332. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1333. {
  1334. struct zfcp_fc_wka_port *wka_port = req->data;
  1335. struct fsf_qtcb_header *header = &req->qtcb->header;
  1336. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1337. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1338. goto out;
  1339. }
  1340. switch (header->fsf_status) {
  1341. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1342. dev_warn(&req->adapter->ccw_device->dev,
  1343. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1344. /* fall through */
  1345. case FSF_ADAPTER_STATUS_AVAILABLE:
  1346. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1347. /* fall through */
  1348. case FSF_ACCESS_DENIED:
  1349. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1350. break;
  1351. case FSF_GOOD:
  1352. wka_port->handle = header->port_handle;
  1353. /* fall through */
  1354. case FSF_PORT_ALREADY_OPEN:
  1355. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1356. }
  1357. out:
  1358. wake_up(&wka_port->completion_wq);
  1359. }
  1360. /**
  1361. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1362. * @wka_port: pointer to struct zfcp_fc_wka_port
  1363. * Returns: 0 on success, error otherwise
  1364. */
  1365. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1366. {
  1367. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1368. struct zfcp_fsf_req *req;
  1369. int retval = -EIO;
  1370. spin_lock_irq(&qdio->req_q_lock);
  1371. if (zfcp_qdio_sbal_get(qdio))
  1372. goto out;
  1373. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1374. SBAL_SFLAGS0_TYPE_READ,
  1375. qdio->adapter->pool.erp_req);
  1376. if (IS_ERR(req)) {
  1377. retval = PTR_ERR(req);
  1378. goto out;
  1379. }
  1380. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1381. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1382. req->handler = zfcp_fsf_open_wka_port_handler;
  1383. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1384. req->data = wka_port;
  1385. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1386. retval = zfcp_fsf_req_send(req);
  1387. if (retval)
  1388. zfcp_fsf_req_free(req);
  1389. out:
  1390. spin_unlock_irq(&qdio->req_q_lock);
  1391. return retval;
  1392. }
  1393. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1394. {
  1395. struct zfcp_fc_wka_port *wka_port = req->data;
  1396. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1397. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1398. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1399. }
  1400. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1401. wake_up(&wka_port->completion_wq);
  1402. }
  1403. /**
  1404. * zfcp_fsf_close_wka_port - create and send close wka port request
  1405. * @wka_port: WKA port to open
  1406. * Returns: 0 on success, error otherwise
  1407. */
  1408. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1409. {
  1410. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1411. struct zfcp_fsf_req *req;
  1412. int retval = -EIO;
  1413. spin_lock_irq(&qdio->req_q_lock);
  1414. if (zfcp_qdio_sbal_get(qdio))
  1415. goto out;
  1416. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1417. SBAL_SFLAGS0_TYPE_READ,
  1418. qdio->adapter->pool.erp_req);
  1419. if (IS_ERR(req)) {
  1420. retval = PTR_ERR(req);
  1421. goto out;
  1422. }
  1423. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1424. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1425. req->handler = zfcp_fsf_close_wka_port_handler;
  1426. req->data = wka_port;
  1427. req->qtcb->header.port_handle = wka_port->handle;
  1428. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1429. retval = zfcp_fsf_req_send(req);
  1430. if (retval)
  1431. zfcp_fsf_req_free(req);
  1432. out:
  1433. spin_unlock_irq(&qdio->req_q_lock);
  1434. return retval;
  1435. }
  1436. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1437. {
  1438. struct zfcp_port *port = req->data;
  1439. struct fsf_qtcb_header *header = &req->qtcb->header;
  1440. struct scsi_device *sdev;
  1441. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1442. return;
  1443. switch (header->fsf_status) {
  1444. case FSF_PORT_HANDLE_NOT_VALID:
  1445. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1446. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1447. break;
  1448. case FSF_ACCESS_DENIED:
  1449. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1450. break;
  1451. case FSF_PORT_BOXED:
  1452. /* can't use generic zfcp_erp_modify_port_status because
  1453. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1454. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1455. shost_for_each_device(sdev, port->adapter->scsi_host)
  1456. if (sdev_to_zfcp(sdev)->port == port)
  1457. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1458. &sdev_to_zfcp(sdev)->status);
  1459. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1460. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1461. "fscpph2");
  1462. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1463. break;
  1464. case FSF_ADAPTER_STATUS_AVAILABLE:
  1465. switch (header->fsf_status_qual.word[0]) {
  1466. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1467. /* fall through */
  1468. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1469. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1470. break;
  1471. }
  1472. break;
  1473. case FSF_GOOD:
  1474. /* can't use generic zfcp_erp_modify_port_status because
  1475. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1476. */
  1477. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1478. shost_for_each_device(sdev, port->adapter->scsi_host)
  1479. if (sdev_to_zfcp(sdev)->port == port)
  1480. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1481. &sdev_to_zfcp(sdev)->status);
  1482. break;
  1483. }
  1484. }
  1485. /**
  1486. * zfcp_fsf_close_physical_port - close physical port
  1487. * @erp_action: pointer to struct zfcp_erp_action
  1488. * Returns: 0 on success
  1489. */
  1490. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1491. {
  1492. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1493. struct zfcp_fsf_req *req;
  1494. int retval = -EIO;
  1495. spin_lock_irq(&qdio->req_q_lock);
  1496. if (zfcp_qdio_sbal_get(qdio))
  1497. goto out;
  1498. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1499. SBAL_SFLAGS0_TYPE_READ,
  1500. qdio->adapter->pool.erp_req);
  1501. if (IS_ERR(req)) {
  1502. retval = PTR_ERR(req);
  1503. goto out;
  1504. }
  1505. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1506. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1507. req->data = erp_action->port;
  1508. req->qtcb->header.port_handle = erp_action->port->handle;
  1509. req->erp_action = erp_action;
  1510. req->handler = zfcp_fsf_close_physical_port_handler;
  1511. erp_action->fsf_req_id = req->req_id;
  1512. zfcp_fsf_start_erp_timer(req);
  1513. retval = zfcp_fsf_req_send(req);
  1514. if (retval) {
  1515. zfcp_fsf_req_free(req);
  1516. erp_action->fsf_req_id = 0;
  1517. }
  1518. out:
  1519. spin_unlock_irq(&qdio->req_q_lock);
  1520. return retval;
  1521. }
  1522. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1523. {
  1524. struct zfcp_adapter *adapter = req->adapter;
  1525. struct scsi_device *sdev = req->data;
  1526. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1527. struct fsf_qtcb_header *header = &req->qtcb->header;
  1528. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1529. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1530. return;
  1531. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1532. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1533. ZFCP_STATUS_LUN_SHARED |
  1534. ZFCP_STATUS_LUN_READONLY,
  1535. &zfcp_sdev->status);
  1536. switch (header->fsf_status) {
  1537. case FSF_PORT_HANDLE_NOT_VALID:
  1538. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1539. /* fall through */
  1540. case FSF_LUN_ALREADY_OPEN:
  1541. break;
  1542. case FSF_ACCESS_DENIED:
  1543. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1544. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1545. break;
  1546. case FSF_PORT_BOXED:
  1547. zfcp_erp_set_port_status(zfcp_sdev->port,
  1548. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1549. zfcp_erp_port_reopen(zfcp_sdev->port,
  1550. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1551. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1552. break;
  1553. case FSF_LUN_SHARING_VIOLATION:
  1554. zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
  1555. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1556. break;
  1557. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1558. dev_warn(&adapter->ccw_device->dev,
  1559. "No handle is available for LUN "
  1560. "0x%016Lx on port 0x%016Lx\n",
  1561. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1562. (unsigned long long)zfcp_sdev->port->wwpn);
  1563. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1564. /* fall through */
  1565. case FSF_INVALID_COMMAND_OPTION:
  1566. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1567. break;
  1568. case FSF_ADAPTER_STATUS_AVAILABLE:
  1569. switch (header->fsf_status_qual.word[0]) {
  1570. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1571. zfcp_fc_test_link(zfcp_sdev->port);
  1572. /* fall through */
  1573. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1574. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1575. break;
  1576. }
  1577. break;
  1578. case FSF_GOOD:
  1579. zfcp_sdev->lun_handle = header->lun_handle;
  1580. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1581. zfcp_cfdc_open_lun_eval(sdev, bottom);
  1582. break;
  1583. }
  1584. }
  1585. /**
  1586. * zfcp_fsf_open_lun - open LUN
  1587. * @erp_action: pointer to struct zfcp_erp_action
  1588. * Returns: 0 on success, error otherwise
  1589. */
  1590. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1591. {
  1592. struct zfcp_adapter *adapter = erp_action->adapter;
  1593. struct zfcp_qdio *qdio = adapter->qdio;
  1594. struct zfcp_fsf_req *req;
  1595. int retval = -EIO;
  1596. spin_lock_irq(&qdio->req_q_lock);
  1597. if (zfcp_qdio_sbal_get(qdio))
  1598. goto out;
  1599. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1600. SBAL_SFLAGS0_TYPE_READ,
  1601. adapter->pool.erp_req);
  1602. if (IS_ERR(req)) {
  1603. retval = PTR_ERR(req);
  1604. goto out;
  1605. }
  1606. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1607. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1608. req->qtcb->header.port_handle = erp_action->port->handle;
  1609. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1610. req->handler = zfcp_fsf_open_lun_handler;
  1611. req->data = erp_action->sdev;
  1612. req->erp_action = erp_action;
  1613. erp_action->fsf_req_id = req->req_id;
  1614. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1615. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1616. zfcp_fsf_start_erp_timer(req);
  1617. retval = zfcp_fsf_req_send(req);
  1618. if (retval) {
  1619. zfcp_fsf_req_free(req);
  1620. erp_action->fsf_req_id = 0;
  1621. }
  1622. out:
  1623. spin_unlock_irq(&qdio->req_q_lock);
  1624. return retval;
  1625. }
  1626. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1627. {
  1628. struct scsi_device *sdev = req->data;
  1629. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1630. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1631. return;
  1632. switch (req->qtcb->header.fsf_status) {
  1633. case FSF_PORT_HANDLE_NOT_VALID:
  1634. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1635. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1636. break;
  1637. case FSF_LUN_HANDLE_NOT_VALID:
  1638. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1639. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1640. break;
  1641. case FSF_PORT_BOXED:
  1642. zfcp_erp_set_port_status(zfcp_sdev->port,
  1643. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1644. zfcp_erp_port_reopen(zfcp_sdev->port,
  1645. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1646. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1647. break;
  1648. case FSF_ADAPTER_STATUS_AVAILABLE:
  1649. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1650. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1651. zfcp_fc_test_link(zfcp_sdev->port);
  1652. /* fall through */
  1653. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1654. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1655. break;
  1656. }
  1657. break;
  1658. case FSF_GOOD:
  1659. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1660. break;
  1661. }
  1662. }
  1663. /**
  1664. * zfcp_fsf_close_LUN - close LUN
  1665. * @erp_action: pointer to erp_action triggering the "close LUN"
  1666. * Returns: 0 on success, error otherwise
  1667. */
  1668. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1669. {
  1670. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1671. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1672. struct zfcp_fsf_req *req;
  1673. int retval = -EIO;
  1674. spin_lock_irq(&qdio->req_q_lock);
  1675. if (zfcp_qdio_sbal_get(qdio))
  1676. goto out;
  1677. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1678. SBAL_SFLAGS0_TYPE_READ,
  1679. qdio->adapter->pool.erp_req);
  1680. if (IS_ERR(req)) {
  1681. retval = PTR_ERR(req);
  1682. goto out;
  1683. }
  1684. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1685. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1686. req->qtcb->header.port_handle = erp_action->port->handle;
  1687. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1688. req->handler = zfcp_fsf_close_lun_handler;
  1689. req->data = erp_action->sdev;
  1690. req->erp_action = erp_action;
  1691. erp_action->fsf_req_id = req->req_id;
  1692. zfcp_fsf_start_erp_timer(req);
  1693. retval = zfcp_fsf_req_send(req);
  1694. if (retval) {
  1695. zfcp_fsf_req_free(req);
  1696. erp_action->fsf_req_id = 0;
  1697. }
  1698. out:
  1699. spin_unlock_irq(&qdio->req_q_lock);
  1700. return retval;
  1701. }
  1702. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1703. {
  1704. lat_rec->sum += lat;
  1705. lat_rec->min = min(lat_rec->min, lat);
  1706. lat_rec->max = max(lat_rec->max, lat);
  1707. }
  1708. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1709. {
  1710. struct fsf_qual_latency_info *lat_in;
  1711. struct latency_cont *lat = NULL;
  1712. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
  1713. struct zfcp_blk_drv_data blktrc;
  1714. int ticks = req->adapter->timer_ticks;
  1715. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1716. blktrc.flags = 0;
  1717. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1718. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1719. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1720. blktrc.inb_usage = 0;
  1721. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1722. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1723. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1724. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1725. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1726. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1727. switch (req->qtcb->bottom.io.data_direction) {
  1728. case FSF_DATADIR_DIF_READ_STRIP:
  1729. case FSF_DATADIR_DIF_READ_CONVERT:
  1730. case FSF_DATADIR_READ:
  1731. lat = &zfcp_sdev->latencies.read;
  1732. break;
  1733. case FSF_DATADIR_DIF_WRITE_INSERT:
  1734. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1735. case FSF_DATADIR_WRITE:
  1736. lat = &zfcp_sdev->latencies.write;
  1737. break;
  1738. case FSF_DATADIR_CMND:
  1739. lat = &zfcp_sdev->latencies.cmd;
  1740. break;
  1741. }
  1742. if (lat) {
  1743. spin_lock(&zfcp_sdev->latencies.lock);
  1744. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1745. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1746. lat->counter++;
  1747. spin_unlock(&zfcp_sdev->latencies.lock);
  1748. }
  1749. }
  1750. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1751. sizeof(blktrc));
  1752. }
  1753. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1754. {
  1755. struct scsi_cmnd *scmnd = req->data;
  1756. struct scsi_device *sdev = scmnd->device;
  1757. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1758. struct fsf_qtcb_header *header = &req->qtcb->header;
  1759. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1760. return;
  1761. switch (header->fsf_status) {
  1762. case FSF_HANDLE_MISMATCH:
  1763. case FSF_PORT_HANDLE_NOT_VALID:
  1764. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1765. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1766. break;
  1767. case FSF_FCPLUN_NOT_VALID:
  1768. case FSF_LUN_HANDLE_NOT_VALID:
  1769. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1771. break;
  1772. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1773. zfcp_fsf_class_not_supp(req);
  1774. break;
  1775. case FSF_ACCESS_DENIED:
  1776. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1777. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1778. break;
  1779. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1780. dev_err(&req->adapter->ccw_device->dev,
  1781. "Incorrect direction %d, LUN 0x%016Lx on port "
  1782. "0x%016Lx closed\n",
  1783. req->qtcb->bottom.io.data_direction,
  1784. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1785. (unsigned long long)zfcp_sdev->port->wwpn);
  1786. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1787. "fssfch3");
  1788. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1789. break;
  1790. case FSF_CMND_LENGTH_NOT_VALID:
  1791. dev_err(&req->adapter->ccw_device->dev,
  1792. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1793. "port 0x%016Lx closed\n",
  1794. req->qtcb->bottom.io.fcp_cmnd_length,
  1795. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1796. (unsigned long long)zfcp_sdev->port->wwpn);
  1797. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1798. "fssfch4");
  1799. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1800. break;
  1801. case FSF_PORT_BOXED:
  1802. zfcp_erp_set_port_status(zfcp_sdev->port,
  1803. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1804. zfcp_erp_port_reopen(zfcp_sdev->port,
  1805. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1806. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1807. break;
  1808. case FSF_LUN_BOXED:
  1809. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1810. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1811. "fssfch6");
  1812. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1813. break;
  1814. case FSF_ADAPTER_STATUS_AVAILABLE:
  1815. if (header->fsf_status_qual.word[0] ==
  1816. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1817. zfcp_fc_test_link(zfcp_sdev->port);
  1818. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1819. break;
  1820. }
  1821. }
  1822. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1823. {
  1824. struct scsi_cmnd *scpnt;
  1825. struct fcp_resp_with_ext *fcp_rsp;
  1826. unsigned long flags;
  1827. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1828. scpnt = req->data;
  1829. if (unlikely(!scpnt)) {
  1830. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1831. return;
  1832. }
  1833. zfcp_fsf_fcp_handler_common(req);
  1834. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1835. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1836. goto skip_fsfstatus;
  1837. }
  1838. switch (req->qtcb->header.fsf_status) {
  1839. case FSF_INCONSISTENT_PROT_DATA:
  1840. case FSF_INVALID_PROT_PARM:
  1841. set_host_byte(scpnt, DID_ERROR);
  1842. goto skip_fsfstatus;
  1843. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1844. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1845. goto skip_fsfstatus;
  1846. case FSF_APP_TAG_CHECK_FAILURE:
  1847. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1848. goto skip_fsfstatus;
  1849. case FSF_REF_TAG_CHECK_FAILURE:
  1850. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1851. goto skip_fsfstatus;
  1852. }
  1853. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1854. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1855. skip_fsfstatus:
  1856. zfcp_fsf_req_trace(req, scpnt);
  1857. zfcp_dbf_scsi_result(scpnt, req);
  1858. scpnt->host_scribble = NULL;
  1859. (scpnt->scsi_done) (scpnt);
  1860. /*
  1861. * We must hold this lock until scsi_done has been called.
  1862. * Otherwise we may call scsi_done after abort regarding this
  1863. * command has completed.
  1864. * Note: scsi_done must not block!
  1865. */
  1866. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1867. }
  1868. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1869. {
  1870. switch (scsi_get_prot_op(scsi_cmnd)) {
  1871. case SCSI_PROT_NORMAL:
  1872. switch (scsi_cmnd->sc_data_direction) {
  1873. case DMA_NONE:
  1874. *data_dir = FSF_DATADIR_CMND;
  1875. break;
  1876. case DMA_FROM_DEVICE:
  1877. *data_dir = FSF_DATADIR_READ;
  1878. break;
  1879. case DMA_TO_DEVICE:
  1880. *data_dir = FSF_DATADIR_WRITE;
  1881. break;
  1882. case DMA_BIDIRECTIONAL:
  1883. return -EINVAL;
  1884. }
  1885. break;
  1886. case SCSI_PROT_READ_STRIP:
  1887. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1888. break;
  1889. case SCSI_PROT_WRITE_INSERT:
  1890. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1891. break;
  1892. case SCSI_PROT_READ_PASS:
  1893. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1894. break;
  1895. case SCSI_PROT_WRITE_PASS:
  1896. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1897. break;
  1898. default:
  1899. return -EINVAL;
  1900. }
  1901. return 0;
  1902. }
  1903. /**
  1904. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1905. * @scsi_cmnd: scsi command to be sent
  1906. */
  1907. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1908. {
  1909. struct zfcp_fsf_req *req;
  1910. struct fcp_cmnd *fcp_cmnd;
  1911. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1912. int retval = -EIO;
  1913. struct scsi_device *sdev = scsi_cmnd->device;
  1914. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1915. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1916. struct zfcp_qdio *qdio = adapter->qdio;
  1917. struct fsf_qtcb_bottom_io *io;
  1918. unsigned long flags;
  1919. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1920. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1921. return -EBUSY;
  1922. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1923. if (atomic_read(&qdio->req_q_free) <= 0) {
  1924. atomic_inc(&qdio->req_q_full);
  1925. goto out;
  1926. }
  1927. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1928. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1929. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1930. sbtype, adapter->pool.scsi_req);
  1931. if (IS_ERR(req)) {
  1932. retval = PTR_ERR(req);
  1933. goto out;
  1934. }
  1935. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1936. io = &req->qtcb->bottom.io;
  1937. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1938. req->data = scsi_cmnd;
  1939. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1940. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1941. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1942. io->service_class = FSF_CLASS_3;
  1943. io->fcp_cmnd_length = FCP_CMND_LEN;
  1944. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1945. io->data_block_length = scsi_cmnd->device->sector_size;
  1946. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1947. }
  1948. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1949. goto failed_scsi_cmnd;
  1950. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1951. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1952. if (scsi_prot_sg_count(scsi_cmnd)) {
  1953. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1954. scsi_prot_sg_count(scsi_cmnd));
  1955. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1956. scsi_prot_sglist(scsi_cmnd));
  1957. if (retval)
  1958. goto failed_scsi_cmnd;
  1959. io->prot_data_length = zfcp_qdio_real_bytes(
  1960. scsi_prot_sglist(scsi_cmnd));
  1961. }
  1962. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1963. scsi_sglist(scsi_cmnd));
  1964. if (unlikely(retval))
  1965. goto failed_scsi_cmnd;
  1966. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1967. if (zfcp_adapter_multi_buffer_active(adapter))
  1968. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1969. retval = zfcp_fsf_req_send(req);
  1970. if (unlikely(retval))
  1971. goto failed_scsi_cmnd;
  1972. goto out;
  1973. failed_scsi_cmnd:
  1974. zfcp_fsf_req_free(req);
  1975. scsi_cmnd->host_scribble = NULL;
  1976. out:
  1977. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1978. return retval;
  1979. }
  1980. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1981. {
  1982. struct fcp_resp_with_ext *fcp_rsp;
  1983. struct fcp_resp_rsp_info *rsp_info;
  1984. zfcp_fsf_fcp_handler_common(req);
  1985. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1986. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1987. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1988. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1989. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1990. }
  1991. /**
  1992. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1993. * @scmnd: SCSI command to send the task management command for
  1994. * @tm_flags: unsigned byte for task management flags
  1995. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1996. */
  1997. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1998. u8 tm_flags)
  1999. {
  2000. struct zfcp_fsf_req *req = NULL;
  2001. struct fcp_cmnd *fcp_cmnd;
  2002. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  2003. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  2004. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  2005. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2006. return NULL;
  2007. spin_lock_irq(&qdio->req_q_lock);
  2008. if (zfcp_qdio_sbal_get(qdio))
  2009. goto out;
  2010. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2011. SBAL_SFLAGS0_TYPE_WRITE,
  2012. qdio->adapter->pool.scsi_req);
  2013. if (IS_ERR(req)) {
  2014. req = NULL;
  2015. goto out;
  2016. }
  2017. req->data = scmnd;
  2018. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2019. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2020. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2021. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2022. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2023. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2024. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2025. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2026. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2027. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2028. if (!zfcp_fsf_req_send(req))
  2029. goto out;
  2030. zfcp_fsf_req_free(req);
  2031. req = NULL;
  2032. out:
  2033. spin_unlock_irq(&qdio->req_q_lock);
  2034. return req;
  2035. }
  2036. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2037. {
  2038. }
  2039. /**
  2040. * zfcp_fsf_control_file - control file upload/download
  2041. * @adapter: pointer to struct zfcp_adapter
  2042. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2043. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2044. */
  2045. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2046. struct zfcp_fsf_cfdc *fsf_cfdc)
  2047. {
  2048. struct zfcp_qdio *qdio = adapter->qdio;
  2049. struct zfcp_fsf_req *req = NULL;
  2050. struct fsf_qtcb_bottom_support *bottom;
  2051. int retval = -EIO;
  2052. u8 direction;
  2053. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2054. return ERR_PTR(-EOPNOTSUPP);
  2055. switch (fsf_cfdc->command) {
  2056. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2057. direction = SBAL_SFLAGS0_TYPE_WRITE;
  2058. break;
  2059. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2060. direction = SBAL_SFLAGS0_TYPE_READ;
  2061. break;
  2062. default:
  2063. return ERR_PTR(-EINVAL);
  2064. }
  2065. spin_lock_irq(&qdio->req_q_lock);
  2066. if (zfcp_qdio_sbal_get(qdio))
  2067. goto out;
  2068. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2069. if (IS_ERR(req)) {
  2070. retval = -EPERM;
  2071. goto out;
  2072. }
  2073. req->handler = zfcp_fsf_control_file_handler;
  2074. bottom = &req->qtcb->bottom.support;
  2075. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2076. bottom->option = fsf_cfdc->option;
  2077. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2078. if (retval ||
  2079. (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
  2080. zfcp_fsf_req_free(req);
  2081. retval = -EIO;
  2082. goto out;
  2083. }
  2084. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2085. if (zfcp_adapter_multi_buffer_active(adapter))
  2086. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  2087. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2088. retval = zfcp_fsf_req_send(req);
  2089. out:
  2090. spin_unlock_irq(&qdio->req_q_lock);
  2091. if (!retval) {
  2092. wait_for_completion(&req->completion);
  2093. return req;
  2094. }
  2095. return ERR_PTR(retval);
  2096. }
  2097. /**
  2098. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2099. * @adapter: pointer to struct zfcp_adapter
  2100. * @sbal_idx: response queue index of SBAL to be processed
  2101. */
  2102. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2103. {
  2104. struct zfcp_adapter *adapter = qdio->adapter;
  2105. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2106. struct qdio_buffer_element *sbale;
  2107. struct zfcp_fsf_req *fsf_req;
  2108. unsigned long req_id;
  2109. int idx;
  2110. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2111. sbale = &sbal->element[idx];
  2112. req_id = (unsigned long) sbale->addr;
  2113. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2114. if (!fsf_req) {
  2115. /*
  2116. * Unknown request means that we have potentially memory
  2117. * corruption and must stop the machine immediately.
  2118. */
  2119. zfcp_qdio_siosl(adapter);
  2120. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2121. req_id, dev_name(&adapter->ccw_device->dev));
  2122. }
  2123. fsf_req->qdio_req.sbal_response = sbal_idx;
  2124. zfcp_fsf_req_complete(fsf_req);
  2125. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2126. break;
  2127. }
  2128. }
  2129. struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
  2130. struct qdio_buffer *sbal)
  2131. {
  2132. struct qdio_buffer_element *sbale = &sbal->element[0];
  2133. u64 req_id = (unsigned long) sbale->addr;
  2134. return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
  2135. }