zfcp_fsf.c 71 KB

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